How would you prevent a fake service or in-memory repository from drifting from the real implementation?
Answer
Define a shared behavioral contract and run the same conformance examples against the fake and the real implementation. Cover schemas, defaults, error semantics, ordering, idempotency and important concurrency behavior; version the contract and run it in CI for both providers. A fake should fail fast on unsupported behavior instead of silently returning convenient results.
Strong answer includes
- runs one contract suite against fake and real implementations
- covers failures and state semantics, not only happy paths
- treats unsupported fake behavior explicitly
Practical example
A team's in-memory repository silently allowed duplicate primary keys while Postgres enforced a unique constraint; a shared contract-test suite that runs against both the fake and the real database catches the mismatch the moment someone adds a test relying on that duplicate-insert behavior.