Test Doubles

Use Martin Fowler's taxonomy:

Double Purpose Example
Dummy Fill a parameter, never used null or empty object
Stub Return canned answers stub.getUser() → User("test")
Spy Record calls for later verification spy.wasCalled("save")
Mock Verify expected interactions mock.verify(save, times: 1)
Fake Working implementation, simplified In-memory database

Fakes SHOULD be preferred over mocks when possible. Fakes exercise real behavior; mocks only verify expectations. A fake in-memory database catches more bugs than a mock that returns canned SQL results.

You MUST NOT mock what you don't own. Wrap external dependencies (HTTP clients, databases, SDKs) behind your own interface. Mock your interface, not the third-party API directly. This insulates tests from upstream API changes.

Platform tools:

version
1.0.0
platforms
csharp, kotlin, python, swift, typescript, web
tags
test-doubles, testing
author
Mike Fullerton
modified
2026-03-27

Change History

Version Date Author Summary
1.0.0 2026-03-27 Mike Fullerton Initial creation