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
- test double — Any object that replaces a real dependency in a test: a stub returns canned data, a fake is a small working implementation, and a mock checks interactions.
- stub — A stand-in for a dependency in a test that simply returns prepared answers, without checking how it was called.
- mock — A test double that stands in for a real dependency and checks that the code under test calls it in the expected way.
- unit test — An automated check of one small piece of code, such as a single function, that runs quickly and on its own.
- contract testing — Testing that an API’s real behaviour matches its written contract, and that its callers only rely on what the contract promises.
Taught in
- Mocking Dependencies — Modern API Architecture: REST, GraphQL & gRPC
- Designing Testable Code — Modern Java: Virtual Threads & High-Throughput Services
- Dependency Injection And The IoC Container — Modern Java: Virtual Threads & High-Throughput Services
- Configuration And Profiles — Modern Java: Virtual Threads & High-Throughput Services
- Tying It All Together — Modern Java: Virtual Threads & High-Throughput Services
- Fakes, Stubs, Mocks And Spies — Automated Testing, TDD & Quality Engineering
- Why Over-Mocking Breeds False Positives — Automated Testing, TDD & Quality Engineering
- Testing With Real Databases — Automated Testing, TDD & Quality Engineering