Lesson 12: Testing, mocks, and seams
When logic calls the clock, the mailer, or the database directly — every test depends on the real world: slow, flaky, and sometimes failing only at midnight. In this lesson we open a seam: a small interface through which we inject a substitute (fake), and get tests that run fast and always give the
A seam is like a wall power socket: you can plug in a real appliance or a test device — and the wall itself never changes.
- Testable design (seams and mocks)
- Hide real dependencies behind small interfaces, so tests can inject substitutes and control every input.
- seam — a swap point for a dependency
- A place in the code where behavior can be replaced from outside — for example a constructor parameter typed as an interface — without editing the logic.
- fake — a fake implementation for tests
- A hand-written implementation of an interface (like FakeClock) whose behavior the test fully controls — making results deterministic.