The fake implements the same interface as the collaborator, shortcuts the storage or the transport, and preserves the observable behaviour the production code depends on.
graph LR P[Production code] --> I[Interface UserRepository] I -->|prod| R[Real SQL repository] I -->|test| F[In-memory fake] R --> DB[(PostgreSQL)] F --> M[Map in memory] style F fill:#E8F5E9 style M fill:#E8F5E9
Three well-known fakes in the wild. H2 and SQLite in-memory replace a real database for integration-style tests. Fake HTTP servers (WireMock, MSW) implement the wire protocol of a partner service. Time fakes (Clock.fixed, freeze_time) replace the system clock so tests that depend on "now" become deterministic. Each one trades a slice of production realism for test speed, reliability and isolation.