Test Doubles Taxonomy¶
Dependencies can be replaced with stand-ins that vary in behavioral fidelity: from completely inert (dummy) to partially functional (stub, spy, mock) to fully functional but simplified (fake) - each trade-off serves different verification needs.
Tension Addressed¶
Isolation vs. Integration
Recognizable As¶
Objects named *Mock, *Stub, *Fake; constructor injection of interfaces; "test mode" configurations; in-memory implementations of storage interfaces; recorded interaction assertions
Canonical Sources¶
Meszaros, "xUnit Test Patterns" (2007); Fowler, "Mocks Aren't Stubs" (2007)
Transfers To¶
Simulation in engineering (model fidelity trade-offs); training environments (simplified versions of production systems); prototyping (stand-ins for unbuilt components)
Sub-concepts: - Dummy: Passed to satisfy signatures, never actually used - Stub: Provides canned responses to specific queries - Spy: Records interactions for later verification - Mock: Pre-programmed with expectations, verifies interactions occurred - Fake: Working implementation unsuitable for production (in-memory database)