Drupal 9 is now end of life and unsupported. If you're stuck on Drupal 7, 8 or 9, get unstuck with a Drupal upgrade roadmap and upgrade to Drupal 10.

Why I prefer integration tests to unit tests

With unit tests, you need to mock everything.

If what you’re testing has a dependency, you need to create and use a mock version.

If the mock has its own dependencies, you need to mock those, too.

I’ve written unit tests with mocks and accidentally only tested the mocks instead of the functionality I intended.

Here’s the thing

With integration tests, you can use and test the real dependencies.

Whilst they may be slightly slower to run, I prefer the simpler setup, less need for mocks, and knowing the real services work - not just the mocked versions.

    Was this useful? Sign up here and get more like this delivered straight to your inbox every day.