fake

A test double that is a small but working implementation of a dependency, such as an in-memory database standing in for a real one.

In more detail

Unlike a stub it has real behaviour, so a test can run a whole flow against it. It must stay simpler than the real dependency, and its assumptions still need checking with integration tests.

Examples

A fixed Clock or an in-memory OrderRepository passed to a constructor in a unit test.
In this course: Fakes cost more to write but can be shared by many tests and exercise real behaviour, so they expose contract mismatches that mocks hide. They can drift from the real thing, which is what contract and integration tests are for.

Related terms

Taught in

References