Problem/Motivation
Currently Drupal test discovery system is looking for Unit/Kernel/Functional/FunctionalJavascript subdirectories within MODULENAME/tests/src directory. There are no possibility for a module to create a base test class/trait and share it between Functional and FunctionalJavascript tests for example.
See \Drupal\simpletest\TestDiscovery:
// Add PHPUnit test namespaces.
$this->testNamespaces["Drupal\\Tests\\$name\\Unit\\"][] = "$base_path/tests/src/Unit";
$this->testNamespaces["Drupal\\Tests\\$name\\Kernel\\"][] = "$base_path/tests/src/Kernel";
$this->testNamespaces["Drupal\\Tests\\$name\\Functional\\"][] = "$base_path/tests/src/Functional";
$this->testNamespaces["Drupal\\Tests\\$name\\FunctionalJavascript\\"][] = "$base_path/tests/src/FunctionalJavascript";
On the other hand, Simpletest allows for any testing configuration within the module:
// Add Simpletest test namespace.
$this->testNamespaces["Drupal\\$name\\Tests\\"][] = "$base_path/src/Tests";
Proposed resolution
Allow adding any configuration of PHPUnit-based tests within modules, but advice to use aforementioned structure.
Remaining tasks
Provide a patch.
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | drupal-improve_phpunit_based_tests_discoverability-2848069-2.patch | 1005 bytes | taran2l |
Comments
Comment #2
taran2lCan we do simple patch like this?
Comment #3
taran2lComment #4
taran2lOK, seems like this is a duplicate :/ of #2605664: [Needs change record updates] Align TestDiscovery and bootstrap.php's non-permissive loading of PSR-4 namespaces for traits