Module Development

Write a Kernel Test for Drupal 8, 9, 10, and 11

Kernel tests in Drupal enable module integration testing with Drupal core systems in a bootstrapped environment. Kernel tests bridge the gap between unit and functional tests. This tutorial focuses on writing kernel tests for the anytown module, specifically to test the ForecastClient service's caching logic and custom username validation.

In this tutorial, we'll:

  • Explore the parts of a kernel test.
  • Write kernel tests for anytown module features.
  • Use mocks and the Drupal container in kernel tests.

By the end of this tutorial, you should be able to get started writing kernel tests to verify your module's integration with Drupal core.

Drupal Module Developer Guide