oliverdavies.uk/source/_daily_emails/2023-11-14.md

825 B

title pubDate permalink tags
Why I prefer integration tests to unit tests 2023-11-14 daily/2023/11/14/why-i-prefer-integration-tests-to-unit-tests
software-development
automated-testing
test-driven-development
mocking

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.