How to write test(s) with specific config to test custom access checks? I have built a custom module that alters some of the User routes (view, edit, delete) to do 3 things:


Forbid account editing, except a user who has 'administer users' permission
Forbid account deleting, except a user who has 'administer users' permission
Forbid account page viewing (/user/{user}) unless that account being viewed has a specific role AND has a boolean field value of TRUE


The accounts are synced from a remote source and logins provisioned by SSO, so, there is no point for anyone to access edit/delete except an admin/dev checking if accounts look correct. 

The first two seem straightforward enough as it requires nothing but setting up some test users with different role permissions and checking the response from an edit or delete route. 

For the third, what is the best way to provide simple configuration to get the field added to the User entity under test? Do I install my entire project config (seems heavy)? Is there a way I can selectively install some config for test only? I think I would just need one or two of the 800 config files to be installed. I checked some of the core tests, but couldn't quite locate one close to what I am asking.
Wound up figuring this out I suppose, although I have no idea if this is the proper way.

Under the custom module I wanted to test, I created a 'tests' directory with a test module and within that new module placed 3 configuration files from my project config ("Show Profile" field storage, "Show Profile" field instance, user form display configuration).

In a functional test, I required that module:

&lt;?php

namespace Drupal\Tests\mymodule\Functional;

use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\Role;

/**
 * Class ProfileAccessTest
 * @package Drupal\Tests\mymodule\Functional
 */
class ProfileAccessTest extends BrowserTestBase {

  /**
   * A set of test users.
   */
  protected $user1, $user2, $user3, $user4;

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['node', 'user', 'mymodule', 'system', 'mymodule_test'];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    $anon_role = Role::load(Role::ANONYMOUS_ID);
    $this-&gt;grantPermissions($anon_role, ['access user profiles']);

    $this-&gt;user1 = $this-&gt;drupalCreateUser(['access content', 'access user profiles'], 'regular_user');
    $this-&gt;user2 = $this-&gt;drupalCreateUser(['administer users'], 'john', TRUE);
    $this-&gt;user3 = $this-&gt;drupalCreateUser([], 'zzz', FALSE);
    $this-&gt;user4 = $this-&gt;drupalCreateUser([], 'yyy', FALSE);
  }

  public function testProfileAccess() {
    // The average user should not be able to do anything to their own account.
    $this-&gt;drupalLogin($this-&gt;user1);
    $this-&gt;drupalGet('/user/' . $this-&gt;user1-&gt;id());
    $this-&gt;assertResponse(403);
    $this-&gt;drupalGet('/user/' . $this-&gt;user1-&gt;id() . '/edit');
    $this-&gt;assertResponse(403);
    $this-&gt;drupalGet('/user/' . $this-&gt;user1-&gt;id() . '/cancel');
    $this-&gt;assertResponse(403);

    $this-&gt;drupalLogin($this-&gt;user2);
    $this-&gt;drupalGet('user/' . $this-&gt;user3-&gt;id() . '/edit');
    $edit['edit-field-show-profile-value'] = 1;
    $this-&gt;drupalPostForm("user/" . $this-&gt;user3-&gt;id() . "/edit", $edit, t('Save'));

    $this-&gt;drupalGet('user/' . $this-&gt;user4-&gt;id() . '/edit');
    $edit['edit-field-show-profile-value'] = 0;
    $this-&gt;drupalPostForm("user/" . $this-&gt;user4-&gt;id() . "/edit", $edit, t('Save'));

    // Any user should be able to view an account with SHOW PROFILE true.
    $this-&gt;drupalLogin($this-&gt;user1);
    $this-&gt;drupalGet('/user/' . $this-&gt;user3-&gt;id());
    $this-&gt;assertResponse(200);

    // But not if SHOW PROFILE is false.
    $this-&gt;drupalGet('/user/' . $this-&gt;user4-&gt;id());
    $this-&gt;assertResponse(403);
  }
}


The tests all pass, which is good.