Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

Previously, the namespace of PHPUnit tests of modules was ambiguous with the module's regular runtime namespace. In addition, the file organization did not allow for different test suites.

The namespace for PHPUnit tests of modules has been changed into Drupal\Tests\$module\Unit:

Type              Classname                      Location
----------------- ------------------------------ ----------------------------
Simpletest        Drupal\foo\Tests\*Test         ./src/Tests/*Test.php
PHPUnit Unit      Drupal\Tests\foo\Unit\*Test    ./tests/src/Unit/*Test.php

In other words:

Type              Base class                     Location
----------------- ------------------------------ ----------------------------
Simpletest        Drupal\simpletest\WebTestBase  ./src/Tests/*Test.php
PHPUnit Unit      Drupal\Tests\UnitTestCase      ./tests/src/Unit/*Test.php

API change

  1. All PHPUnit unit test files in modules are moved into a Unit subdirectory.

    -./tests/src/
    +./tests/src/Unit/
    
  2. The namespace is changed from Drupal\mymodule\Tests to Drupal\Tests\mymodule:

    -Drupal\mymodule\Tests\FooTest
    +Drupal\Tests\mymodule\Unit\FooTest
    

Example

--- a/core/modules/system/tests/src/Controller/SystemControllerTest.php
+++ b/core/modules/system/tests/src/Unit/Controller/SystemControllerTest.php
@@ -2,10 +2,10 @@
 
 /**
  * @file
- * Contains \Drupal\system\Tests\Controller\SystemControllerTest.
+ * Contains \Drupal\Tests\system\Unit\Controller\SystemControllerTest.
  */
 
-namespace Drupal\system\Tests\Controller;
+namespace Drupal\Tests\system\Unit\Controller;
Impacts: 
Module developers