Skip to content
← The curriculum

The double that drifted

Stub, mock, fake, spy — and the failure mode all four share.

There are four things people mean by "mock", and confusing them is how test suites become unmaintainable.

A stub returns canned answers. A spy records how it was called. A mock is a spy with expectations baked in — it fails the test itself if it was not called correctly. A fake is a real working implementation, just a simpler one: an in-memory store standing in for a database.

The rule of thumb: stub what you query, spy on what you command, use a fake when the collaborator has real behaviour you depend on, and reach for a mock rarely, because a mock couples your test to the shape of a call rather than to the result of it.

1 of 4