Running Automated Tests in Drupal

Learn about the different ways to run Drupal’s automated tests, the differences between them, and how to debug failing tests during development.

This course covers the use of both the run-tests.sh script included with Drupal core and the PHPUnit binary for running tests, detailing the setup and configuration required for each method. Learners will gain practical skills in running unit, kernel, functional, and functional JavaScript tests, understanding the differences and use cases for each type. Additionally, the course will provide insights into managing test environments, interpreting test results, and integrating testing into continuous integration workflows.

Key topics

  • Using the run-tests.sh script included with Drupal core
  • Running tests with PHPUnit
  • Setting up testing dependencies
  • Interpreting test results
  • Debugging failing tests
Tutorials in this course
More information

Drupal core comes with a run-tests.sh script to help with running tests. This script has some distinct advantages over running tests directly via PHPUnit. It runs all tests in their own separate process, and can therefore handle PHP fatal errors without killing the test run. It's also the mechanism that the Drupal CI tools use to run tests; so, it can be handy when debugging tests that are failing on Drupal.org.

In this tutorial we'll:

  • Look at the available options for the core run-tests.sh script
  • Go through some examples of running tests using run-tests.sh

By the end of this tutorial you'll know how to run your tests using run-test.sh.

Categories
Drupal 8, 9, and 10
More information

In this tutorial, we'll run tests in several different ways using the PHPUnit tools available in Drupal. We'll learn about various environment variables you'll need to supply to the test runner depending on which type of test you're running. And we'll learn various ways to get reports on the test results. By the end of this tutorial, you should understand how to run Drupal tests using PHPUnit.

This course appears in the following guides:
Module Development
Learn how to run and write unit, kernel, and functional tests for your custom Drupal code.

Test Custom Code