27 lines
827 B
Markdown
27 lines
827 B
Markdown
|
---
|
||
|
title: >
|
||
|
Why I prefer integration tests to unit tests
|
||
|
pubDate: 2023-11-14
|
||
|
permalink: >-
|
||
|
archive/2023/11/14/why-i-prefer-integration-tests-to-unit-tests
|
||
|
tags:
|
||
|
- 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.
|