Registering tests

There are certain commonalities between the various test suite types regarding what we need to do in order for Drupal (and PHPUnit) to be able to discover and run them.

First, we have the directory placement where the test classes should go in. The pattern is this--tests/src/[suite_type] where [suite_type] is a name of the test suite type this test should be. Also, it can be one of the following:

Unit
Kernel
Functional
FunctionalJavascript

So, for example, unit tests would go inside the tests/src/Unit folder of our module.

Second, the test classes need to respect a namespace structure as well:

namespace Drupal\Tests\[module_name]\[suite_type]

This is also pretty straightforward to understand.

Third, there is a certain metadata ...

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.