How to run test cases in Drupal?

Testing module in Drupal is useful for running automated test cases. It can be used to verify the working state of Drupal before and after any code changes.

This article explains how to run test cases in Drupal.

This applies to:

  • Drupal 7.x

Step (1). Log-in into your Drupal based website as an administrator.

Step (2). Click on Configuration link which is on top of the page. It will display Configuration page.

Drupal - Configuration -Development - Testing

Drupal – Configuration -Development – Testing

Step (3). Click on Testing link which is under DEVELOPMENT section. It will display Testing page.

This link will be available only when Testing module is enabled.

Step (4). Testing page will display list of available test cases in test groups.

Drupal - Testing page

Drupal – Testing page

  • By clicking on arrow mark before the test group, you can expand/collapse the test group.
  • When the test group is expanded, it will display all the available test cases under the test group.
  • You can select each test case by selecting the check-box before the test case.
  • You can also select all the test cases with-in the test case by selecting the check-box before the test group.

Step (5). Select the test cases you want to execute. Note that, if you select all the test cases, it might take several minutes for all tests to complete.

Drupal - Testing - Expanded test group

Drupal – Testing – Expanded test group

Step (6). Scroll down the page and click on Run tests button to execute the selected test cases.

Step (7). It will display Running tests page showing test cases execution progress.

Drupal - Running tests page

Drupal – Running tests page

Step (8). Once the running the test cases are completed, it will display Test result page.

Drupal - Test result page

Drupal – Test result page

Step (9). A message will be displayed next to each test group indicating whether test cases within it is passed, failed or had an exception.

  • A pass means that the test returned expected results
  • Fail means that the test did not returned expected results.
  • An exception normally indicates an error outside of the test.

Step (10). If there were failures or exceptions, the test results will be expanded to show the details, and the tests that had failures or exceptions will be indicated in red or pink rows.

Drupal - Test results

Drupal – Test results

Step (11). You can also re-run failed test cases. On Test result page:

  • Select the Fail item from Filter combo box in ACTIONS section.
  • Click on Run tests button to re-run the failed test case.

You can use these test results to refine your code and tests, until all tests pass.

by Code Steps

Leave a Reply