Running module unit tests from CLI: "Class '..' could not be found" I am trying to run module-provided PhpUnit tests from the CLI.

Following these instructions, so my core/phpunit.xml should be correct now.

Using this command:

cd core
../vendor/bin/phpunit modules/system/src/Tests/Installer/InstallerTranslationTest.php


I get this output:

Class 'modules/system/src/Tests/Installer/InstallerTranslationTest' could not be found in '/****/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php'.


Module-provided tests in e.g. core/modules/system/tests/src/.., are found, and work correctly with the phpunit command. But tests in core/modules/system/src/Tests/.. do not seem to work, or be detected.

(I think I had this problem before, and someone told me what was missing. But I don't remember anything. Time to document this in this Q/A site.)
Ok, so the solution is

From Drupal root directory:

sudo -u www-data php core/scripts/run-tests.sh --url http://d8.localhost/ --class "Drupal\system\Tests\Installer\InstallerTranslationTest"


Assuming that your site is available under http://d8.localhost, and it is an installed site.

Maybe you want to use --verbose for more output.

Documentation on drupal.org: Running Tests Through command-line