BrowserTest on a multisite gives an error My sites directory looks like this:

default, site1, site2, site3.  

The default directory is empty. I want to run tests against my site1 database. So I have put its details in phpunit.xml

Here is my phpunit.xml set up. 

  &lt;php&gt;
    &lt;!-- Set error reporting to E_ALL. --&gt;
    &lt;ini name="error_reporting" value="32767"/&gt;
    &lt;!-- Do not limit the amount of memory tests take to run. --&gt;
    &lt;ini name="memory_limit" value="-1"/&gt;
    &lt;!-- Example SIMPLETEST_BASE_URL value: http://localhost --&gt;
    &lt;env name="SIMPLETEST_BASE_URL" value="http://d8.site1.dev"/&gt;
    &lt;!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix --&gt;
    &lt;env name="SIMPLETEST_DB" value="mysql://site1:site1@localhost/site1"/&gt;
    &lt;!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output --&gt;
    &lt;env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/&gt;
  &lt;/php&gt;


And then my actual test: 

&lt;?php

namespace Drupal\Tests\my_module\Functional;

use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;

/**
 * Simple test to ensure that main page loads with module enabled.
 *
 * @group my_module_tests
 */
class LoadTest extends BrowserTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = ['my_module'];

  /**
   * A user with permission to administer site configuration.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $user;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this-&gt;user = $this-&gt;drupalCreateUser(['administer site configuration']);
    $this-&gt;drupalLogin($this-&gt;user);
  }

  /**
   * Tests that the home page loads with a 200 response.
   */
  public function testLoad() {
    $this-&gt;drupalGet('node/add/product_list_page');
    $this-&gt;assertResponse(200);
  }

}


Then from the core directory of Drupal I run: 

../../vendor/bin/phpunit --group my_module_group


Then I get this error: 

1) Drupal\Tests\my_module\Functional\LoadTest::testLoad
copy(/var/www/site/docroot/sites/default/default.settings.php): failed to open stream: No such file or directory

Why is it looking in my empty default directory and not site1 for this file?
It is possible to have a multisite directory setup with PHP Unit.

Since your default directory is empty, I suggest creating a symbolic link from the default directory to the site1 directory. You can do that by using commands similar to this one from sites directory.

ln -s sites1 default


Not sure, but you may also need to adjust the $sites variable in sites.php.

Also, make sure you specify a printerClass like this in the last line.

&lt;phpunit bootstrap="tests/bootstrap.php" colors="true"
         beStrictAboutTestsThatDoNotTestAnything="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutChangesToGlobalState="true"
         checkForUnintentionallyCoveredCode="false"
         printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter"&gt;


Here is what my php tag looks like in phpunit.xml (I use SQLite though and specify an output directory.) You may need to adjust directory permissions so that it is writable. I test on my remote machine with a FQDN, not sure if that is ideal though.

&lt;php&gt;
    &lt;!-- Set error reporting to E_ALL. --&gt;
    &lt;ini name="error_reporting" value="32767"/&gt;
    &lt;!-- Do not limit the amount of memory tests take to run. --&gt;
    &lt;ini name="memory_limit" value="-1"/&gt;
    &lt;!-- Example SIMPLETEST_BASE_URL value: http://localhost --&gt;
    &lt;env name="SIMPLETEST_BASE_URL" value="https://dev.example.com"/&gt;
    &lt;!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix --&gt;
    &lt;env name="SIMPLETEST_DB" value="sqlite://dev.example.com/sites/dev.example.com/files/.ht.sqlite"/&gt;
    &lt;!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output --&gt;
    &lt;env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/path/to/document/root/sites/dev.example.com/files/simpletest/browser_output"/&gt;
&lt;/php&gt;


Also, I run the phpunit command from the Drupal core directory like this (I do not use group ID but I know it may be possible.

sudo -u www-data ../vendor/bin/phpunit ../modules/contrib/example/tests/src/Functional/ExampleHomepageTest.php


Here is what my test looks like. It will need the correct directory structure and classname.

&lt;?php

namespace Drupal\Tests\example\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Tests to ensure Example.com Homepage is reachable
 *
 * @group example_ui
 */
class ExampleHomepageTest extends BrowserTestBase {

/**
 * Modules to enable.
 *
 * @var array
 */
protected static $modules = ['node', 'user'];

protected $profile = 'standard';

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

}

/**
  * Tests that the reaction rule listing page works.
  */
public function testHomepage() {

  $account = $this-&gt;drupalCreateUser(array('administer site configuration'));
  $this-&gt;drupalLogin($account);

  $this-&gt;drupalGet('&lt;front&gt;');
  $this-&gt;assertSession()-&gt;statusCodeEquals(200);
  $this-&gt;assertSession()-&gt;pageTextContains('cleaning');
 }
}


This page will be useful: https://www.drupal.org/docs/8/phpunit