Mock → Fake: Why Fakes Survive Refactoring
Watch what happens when you refactor code tested with mocks. The mock test breaks. The fake test passes. Same refactoring, different outcome.
Mocks couple to HOW. Fakes couple to WHAT.
The Problem
A test that patches app.smtplib.SMTP is coupled to the implementation. When the service switches from SMTP to an HTTP API, the mock explodes — even though the behavior is identical.
The Solution
Define an EmailPort protocol. The service depends on the port, not the transport. A simple fake implements the port. Same refactoring, same test, it passes.