Skip to content

Why it matters

Fakes let tests exercise real behaviour without the cost and fragility of the real dependency; they are the only double that can sit in the middle of a domain test without collapsing the logic.

A test with a stub checks "what happens when find returns X". A test with a fake checks "what happens when the repository works". That difference is significant: the first tests a branch, the second tests a workflow. Martin Fowler argues that fakes are usually the best choice for state verification (checking results), while spies/mocks are best for interaction verification (checking calls) [1].

The cost is maintenance. A fake is production code that happens to live in tests: it must stay in sync with the real interface, it must implement the same contract, and it must not be used in production where its shortcuts become bugs. Martin Fowler's Mocks Aren't Stubs (2007) and the broader "classicist vs mockist" debate in the TDD community settled on a pragmatic line: fakes where behaviour is stable and complex, mocks where the collaboration matters more than the outcome.