Test Behavior, Not Implementation
🌳 Evergreen ·
Test what a system does (brains), not how it does it (nerves). Tests coupled to implementation details break during legitimate refactoring and provide false confidence. They pass when the wiring is correct but miss behavioral bugs. A test that asserts “given input X, the output is Y” survives refactoring. A test that asserts “method A calls method B with argument C” breaks the moment you restructure internals.
The fix: test at the public interface boundary. Provide inputs, assert on outputs and observable side effects. Let the implementation be free to change. When tests mirror production code structure line-by-line or require deep knowledge of internals to set up, they’re mocks-vs-stubs.
Connections
- 🌳Behavioral Tests vs. Architectural Coherence Tests
- 🌳Detroit vs. London Schools of Unit Testing
- 🌳Minimize Public Surface for Testability
- 🌳Mocks in Testing
- 🌳Mocks vs. Stubs: When to Use Which
- 🌳Stubs in Testing
- 🌳Tests as a Refactoring Safety Net
- 🌳Tests Exist for Maintainability
- 🌳Unit Test Attribute Trilemma
- 🪶Unit test the brains and not the nerves