Software Engineering ยท Testing
A test double that stands in for a real dependency and lets you verify how it was called โ e.g. that a specific method ran with the expected arguments.
Mental model: Like a training dummy standing in for a real person during CPR practice.
Example: A test that swaps a real EmailService for a mock and asserts sendEmail() was called with the right recipient, without actually sending anything.
In practice: Overusing mocks can make a test pass even when the real integration is broken, since you're only verifying the fake's behavior โ integration tests exist to catch what mocks miss.
Debated: Heavily contested โ the 'London school' of TDD builds tests almost entirely around mocks, while the 'classicist' school treats heavy mocking as a sign your design has too many seams.