Spy and Mock Strategies
Compare spies, stubs, and fakes as test double strategies and when each is the right level of fidelity.
Not every test double needs to be built the same way, and interviewers ask about this to see whether you can reason about the right level of fidelity for a given test rather than reflexively reaching for the same mocking approach every time. A spy wraps an existing real function/method, letting it optionally still call through to the real implementation while recording how it was called (arguments, call count) — useful when you want to verify an interaction happened without necessarily replacing the underlying behavior.
A spy is like a hidden camera on a real cashier, recording exactly what happened without changing how the register works; a stub is like a vending machine rigged to always dispense the same snack no matter which button is pressed; a fake is like a fully functioning play-money economy used in a classroom simulation — realistic enough to practice with, but not connected to any real bank.