When running tests in Drupal 11.3.0+ you might see an error that looks like this:
1) /var/www/html/web/core/tests/Drupal/Tests/BrowserTestBase.php:334
Functional/FunctionalJavascript test classes must specify the #[RunTestsInSeparateProcesses] attribute, not doing so is deprecated in drupal:
11.3.0 and is throwing an exception in drupal:12.0.0. See https://www.drupal.org/node/3548485This is because of a change in PHPUnit 12, which previously allowed process isolation to be defined in the abstract base classes. Classes must define the fact that they must be tested in process isolation within the concrete class itself.
Therefore, all concrete test class, Kernel, Functional and FunctionalJavascript, must specifiy a #[RunTestsInSeparateProcesses] attribute on the class level.
To fix this, you just need to add the following use statement to the top of your class.
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;And then add the attribute to the class definition.
#[RunTestsInSeparateProcesses]
class SomeTest extends BrowserTestBase {With this in place, the test will run without deprecations. There might be other attributes defined in the class, so just needs to be added to those attributes.
See https://www.drupal.org/node/3548485 for information on this.
Add new comment