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.

- Oliver

P.S. Do you need immediate access to an expert Drupal Developer? With my Drupal development subscription, make unlimited requests for a fixed monthly price in less time than posting to a job board!

Was this interesting?

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

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.