Automated Testing in Drupal

Automated testing helps ensure code quality, catch bugs early, and maintain reliability across updates and deployments, leading to more stable and maintainable projects.

This course covers the importance of testing, the different types of tests available in Drupal, and how to organize and run these tests using tools like PHPUnit. Additionally, learners will gain practical knowledge on installing necessary development dependencies, structuring test files, and understanding the various testing frameworks provided by Drupal core.

Key topics

  • Why testing custom code is important
  • The different types of tests including unit tests, kernel tests, and functional tests
  • Testing frameworks included in Drupal and their specific use cases
  • Running tests with PHPUnit
  • Set up a development environment for testing
  • Strategies like Test-Driven Development (TDD) and Continuous Integration (CI)
  • Terminology and concepts related to automated testing
  • Practical examples
Tutorials in this course
Categories
Drupal 8, 9, and 10
More information

In this gentle introduction to testing, we'll walk through what testing is and why it's important to your project. Then we'll define some terms you'll be likely to see while working with tests so that we're all on the same page. After reading through this tutorial you'll understand enough of the basic vocabulary to get started running (and eventually writing) tests for your Drupal site.

Categories
Drupal 8, 9, and 10
More information

This tutorial will clarify some basic ideas about software testing. We'll give some strategies for testing and illustrate types of tests and when and why you'd use them. This document is written with Drupal in mind, but the concepts apply for other development environments you'll encounter as well. The tools will be different, but the ideas apply universally. By the end of this tutorial, you should understand what testing is for and how different types of tests support different purposes and outcomes.

More information

In this tutorial, we will look at the various types of tests and testing frameworks included in Drupal core. We'll also provide an overview of how the different frameworks operate and the types of situations where each of the different frameworks is useful.

More information

In order to run tests, your Drupal site needs additional development requirements installed using Composer.

By default, when you download Drupal as a zip file or tarball, these packages will not be installed, since they're used for development purposes.

In this tutorial, we'll walk through the steps to make sure we've got Composer available. Next we'll install the dependencies. Then we'll talk about why you shouldn't have development dependencies available on your production site. Thankfully, Composer can help make this easy to manage.

Categories
Drupal 8, 9, and 10
More information

In order for Drupal to be able to locate and run the tests you create, the files need to be put in the correct place. In this tutorial, we'll take a look at the different types of test frameworks that are included along with core. We'll also see how Drupal expects our test files to be organized so that the test runners can find them.

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