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

In Drupal 7 (and below), all test classes had to implement a public static getInfo() method in order to supply meta data about the test (for UI/listing purposes). In Drupal 8, the getInfo() method has been replaced with native PHPDoc documentation on the test class itself, following PHPUnit's lead:

  1. The fully-qualified test class name is the (reported) test 'name' now.

  2. The PHPDoc summary line is consumed as the 'description' now.

    Every test class MUST have a PHPDoc summary line. Only PHPUnit tests MAY skip the PHPDoc summary line if their PHPDoc specifies a @coversDefaultClass.

  3. The @group PHPDoc annotation replaces the 'group'.

    Every test class MUST specify at least one (first) @group that matches the originating module name (or Drupal core component name).

    For example, the former human-readable 'group' => 'Views UI' turns into the module name @group views_ui

  4. The @requires module $name PHPDoc annotation replaces the 'dependencies'.

    This PHPDoc annotation construct follows the generic pattern of PHPUnit @requires annotations. Note that Simpletest tests only support exactly this requirement at this point; additional options will be made available by #1273478: Implement @requires and @dependencies within TestBase, mark tests as skipped

PHPUnit tests no longer need to implement getInfo() — which implicitly means that PHPUnit tests no longer have to extend from Drupal\Tests\UnitTestCase instead of \PHPUnit_Framework_TestCase (if unnecessary).


Example: IceCreamTest class of ice_cream.module

Drupal 7

/**
 * Tests generation of ice cream.
 */
class IceCreamTest extends DrupalWebTestCase {

  public function getInfo() {
    return array(
      'name' => 'Make ice cream',
      'description' => 'Tests generation of ice cream.',
      'group' => 'Ice Cream', // Note: Capitalization.
    );
  }

}

Drupal 8

Drupal tests

/**
 * Tests generation of ice cream.
 *
 * @group ice_cream
 *
 * Note: This ^^ primary group is the internal name of the originating module.
 */
class IceCreamTest extends WebTestBase {
}

PHPUnit tests

(only applies if there is a @coversDefaultClass; otherwise see above.)

/**
 * @coversDefaultClass \Drupal\ice_cream\IceCream
 * @group ice_cream
 */
class IceCreamTest extends UnitTestCase {
}
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done