Integration vs Unit Tests
- Unit tests test a single function or method in isolation. The inputs and expected outputs are for that specific function only.
- Integration tests test multiple components working together through a real execution path.
A bug in any of those components would cause the integration test to fail, but it wouldn’t tell you which layer broke. That’s the tradeoff:
| Unit | Integration | |
|---|---|---|
| Scope | One function | Multiple components |
| Failure diagnosis | Pinpoints the broken function | Tells you something broke |
| Fragility | Only breaks if its target changes | Breaks if any layer changes |
| Confidence | Function works correctly | Functions work correctly together |
You want both: unit tests to catch and locate bugs quickly, integration tests to verify the pieces actually compose correctly.