Drupal 8  8.0.2
Automated tests

Data Structures

class  BrowserTestBase
 
class  WebTestBase
 
class  UnitTestCase
 

Detailed Description

Overview of PHPUnit tests and Simpletest tests.

The Drupal project has embraced a philosophy of using automated tests, consisting of both unit tests (which test the functionality of classes at a low level) and functional tests (which test the functionality of Drupal systems at a higher level, usually involving web output). The goal is to have test coverage for all or most of the components and features, and to run the automated tests before any code is changed or added, to make sure it doesn't break any existing functionality (regression testing).

In order to implement this philosophy, developers need to do the following:

Writing PHPUnit tests for classes

PHPUnit tests for classes are written using the industry-standard PHPUnit framework. Use a PHPUnit test to test functionality of a class if the Drupal environment (database, settings, etc.) and web browser are not needed for the test, or if the Drupal environment can be replaced by a "mock" object. To write a PHPUnit test:

Writing functional tests

Functional tests are written using a Drupal-specific framework that is, for historical reasons, known as "Simpletest". Use a Simpletest test to test the functionality of sub-system of Drupal, if the functionality depends on the Drupal database and settings, or to test the web output of Drupal. To write a Simpletest test:

Running tests

You can run both Simpletest and PHPUnit tests by enabling the core Testing module (core/modules/simpletest). Once that module is enabled, tests can be run using the core/scripts/run-tests.sh script, using Drush , or from the Testing module user interface.

PHPUnit tests can also be run from the command line, using the PHPUnit framework. See https://www.drupal.org/node/2116263 for more information.