Testing·Intermediate·Conceptual·1 min read
What is the difference between a stub, a mock, and a spy?
Short interview answer
A stub returns canned data without caring how it's called. A mock is a stub that also asserts specific calls and arguments happened. A spy wraps a real implementation and records calls while still letting the real behavior run unless configured otherwise.
Key takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.