Overspecification is a testing anti-pattern: tests become coupled to the system under test’s implementation details instead of verifying externally observable behavior. Prefer tests that describe what a unit does over tests that prescribe which classes, collaborators, or call sequences it must use. section 2.5
Use these distinctions to recognize and reduce overspecification:
- Treat tests that verify units of code, mock interactions, or internal collaborator communication as warning signs when they replace behavioral verification. section 2.3 section 2.5
- Remember that test doubles can hide a design problem rather than solve the inability to test a piece of code. section 2.5
- Accept some failure cascading when it reveals that a widely depended-on piece of code has been broken; minimizing individual failure locations is not the primary goal. section 2.3
Behavior versus implementation
A behavior-focused test asks, “When I call my dog, does he come right to me?” An overspecified test checks the internal sequence instead: which leg moves first, when the head turns, and when the tail starts wagging. The first test protects observable behavior; the second couples the test to implementation details. section 2.3
When I call my dog, he comes right to me.
Use the concise dog-call statement as the behavioral specification. section 2.3
When I call my dog, he moves his front left leg first, then the front right leg, his head turns, the tail start wagging...
Contrast the behavioral statement with a detailed internal sequence to spot overspecification. section 2.3
