Difficulty running tests, --group option not being respected I am trying to run a BrowserTestBase based test in my own module, following the documentation on drupal.org.

No matter if I run the test from PHPStorm or command line, I get the same error:

vagrant@local:/var/www/mysite/docroot$ ../vendor/bin/phpunit -c core/phpunit.xml --group mymodule
PHP Fatal error:  Trait 'Drupal\Tests\facets\Functional\BlockTestTrait' not found in /var/www/mysite/docroot/modules/contrib/search_api_solr/tests/src/Functional/FacetsTest.php on line 20
PHP Stack trace:
PHP   1. {main}() /var/www/mysite/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /var/www/mysite/vendor/phpunit/phpunit/phpunit:52
PHP   3. PHPUnit_TextUI_Command-&gt;run() /var/www/mysite/vendor/phpunit/phpunit/src/TextUI/Command.php:100
PHP   4. PHPUnit_TextUI_Command-&gt;handleArguments() /var/www/mysite/vendor/phpunit/phpunit/src/TextUI/Command.php:111
PHP   5. PHPUnit_Util_Configuration-&gt;getTestSuiteConfiguration() /var/www/mysite/vendor/phpunit/phpunit/src/TextUI/Command.php:649
PHP   6. PHPUnit_Util_Configuration-&gt;getTestSuite() /var/www/mysite/vendor/phpunit/phpunit/src/Util/Configuration.php:878
PHP   7. PHPUnit_Framework_TestSuite-&gt;addTestFile() /var/www/mysite/vendor/phpunit/phpunit/src/Util/Configuration.php:1000
PHP   8. ReflectionMethod-&gt;invoke() /var/www/mysite/vendor/phpunit/phpunit/src/Framework/TestSuite.php:353
PHP   9. Drupal\Tests\TestSuites\FunctionalTestSuite::suite() /var/www/mysite/vendor/phpunit/phpunit/src/Framework/TestSuite.php:353
PHP  10. Drupal\Tests\TestSuites\TestSuiteBase-&gt;addTestsBySuiteNamespace() /var/www/mysite/docroot/core/tests/TestSuites/FunctionalTestSuite.php:22
PHP  11. PHPUnit_Framework_TestSuite-&gt;addTestFiles() /var/www/mysite/docroot/core/tests/TestSuites/TestSuiteBase.php:55
PHP  12. PHPUnit_Framework_TestSuite-&gt;addTestFile() /var/www/mysite/vendor/phpunit/phpunit/src/Framework/TestSuite.php:384
PHP  13. PHPUnit_Util_Fileloader::checkAndLoad() /var/www/mysite/vendor/phpunit/phpunit/src/Framework/TestSuite.php:310
PHP  14. PHPUnit_Util_Fileloader::load() /var/www/mysite/vendor/phpunit/phpunit/src/Util/Fileloader.php:38
PHP  15. include_once() /var/www/mysite/vendor/phpunit/phpunit/src/Util/Fileloader.php:56

Fatal error: Trait 'Drupal\Tests\facets\Functional\BlockTestTrait' not found in /var/www/mysite/docroot/modules/contrib/search_api_solr/tests/src/Functional/FacetsTest.php on line 20


I am not requiring Search API Solr in my test, nor do I have a clue why it is running it. Even if I specify --testsuite unit, I get the same error.

Here is the test I am trying to run, with a basic test step:

namespace Drupal\Tests\mymodule\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Class AuthenticationTest.
 *
 * @group mymodule
 */
class AuthenticationTest extends BrowserTestBase {

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

  public function setUp() {
    parent::setUp();

    // set config for netforum
  }

  /**
   * The superuser should not authenticate to Netforum.
   */
  public function testAdminUserUsesDrupalAuthentication() {
    $account = $this-&gt;drupalCreateUser(['administer site configuration']);
    $this-&gt;drupalLogin($account);
  }

}


I am not sure why it is even looking at the Search API Solr module, but the test in question does try to use several files that do not exist:

use Drupal\Tests\facets\Functional\BlockTestTrait;
use Drupal\Tests\facets\Functional\ExampleContentTrait;
use Drupal\Tests\facets\Functional\TestHelperTrait;


I assume these are a part of the Facets module, which I do not have.

edit: This might be my issue.
edit: This might be my issue.


Yes.

The error happens during test discovery, first it has to find all tests and then limit it based on the group.

The easiest workaround is simply to specifiy your module, then you don't even need the group. phpunit will only discover test in that folder, which will not just avoid this problem it will also be much faster.

$ ../vendor/bin/phpunit -c core/phpunit.xml modules/custom/mymodule