Comparison
FakevsStub
Fake
you write a working in-memory version of the repository, with real behaviour, just not one backed by a database.
A double with a real, working implementation that is unsuitable for production — an in-memory store, an embedded database, a local queue. It lets tests exercise genuine behaviour without the real dependency's cost. The risk is divergence: a fake that behaves differently from the real thing gives you green tests and a broken system.
Full entry →Stub
you hard-code the collaborator to return a fixed value so the code under test has something to work with.
A double that returns canned responses, providing inputs to the code under test. It has no assertions and no logic; it exists so the test can reach the code path you care about. If your test asserts on what the stub was called with, you have written a mock.
Full entry →