By mile23 on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.4.x
Introduced in version:
8.4.0
Issue links:
Description:
If your KernelTestBase or BrowserTestBase test needs a specific module to be in the file system, you can annotate that dependency and the test will be marked as skipped if it's not present.
This works for both class annotations and method annotations.
Previously, tests annotated this way were ignored by TestDiscovery if the requirement was not met. This change marks the test as skipped within the PHPUnit framework, allowing for visibility at test time.
Example of a test class with a module requirement:
/**
* A test class which requires a module.
*
* @requires module modulename
* @group example
*/
class ExampleTest extends KernelTestBase {
protected static $modules = ['modulename'];
}
Example of a test class method with a module requirement:
/**
* A test class with a method which requires a module.
*
* @group example
*/
class ExampleTest extends KernelTestBase {
protected static $modules = ['apimodule'];
/**
* This method will be skipped if the module is not present.
*
* @requires module ui_apimodule
*/
public function testUiIfPresent() {
// Use the module in this test...
}
}
Impacts:
Module developers
Comments
This does not work
This does not work