jargon

Comparison

MockvsSpy

Mock

you assert that the email service was called exactly once with this address, and the test fails if it was not.

A double with pre-programmed expectations about how it will be called, which fails the test when they are not met. It verifies interactions rather than results, which is right when the observable effect is the call itself — an email sent, a message published. Overusing mocks welds the test to the implementation, so refactoring breaks tests without breaking behaviour.

Full entry →

Spy

you wrap the real thing, let it do its actual job, and record the calls so you can check them afterwards.

A double that records how it was used for later assertion, often wrapping a real implementation. Unlike a mock it does not set expectations up front — you assert after the fact, which reads more naturally and couples less. It is the middle ground between a stub that asserts nothing and a mock that asserts everything.

Full entry →

Related comparisons