Three Ways to Fake a Dependency, and When Each One Lies to You

"Mock it," "virtualize it," and "write a contract test" get used almost interchangeably in casual conversation, but they're answers to three different questions, and picking the wrong one doesn't just waste effort — it gives you a specific, different flavor of false confidence.
Mocking: fast, cheap, and only as good as what you configured
A mock is a stand-in that returns what you tell it to return. It's fast to set up, doesn't need the real dependency's infrastructure, and is the right tool when the question is "does my code handle this specific response correctly" — a 404, a particular JSON shape, a slow response, a dropped connection. Its failure mode is contract drift: the mock is only as accurate as whoever configured it, and nothing forces it to stay in sync if the real dependency's behavior changes underneath it.
Service virtualization: higher fidelity, aimed at a different problem
Service virtualization is what you reach for when a mock's simplicity stops being enough — typically because the dependency's behavior under load, its stateful multi-step flows, or its performance characteristics are what you're actually testing, not just one response shape. A virtualized service is meant to stand in for a whole dependent system convincingly enough to run realistic load or performance tests against, which is overhead a simple mock isn't built to carry and usually doesn't need to. If the question is "does my endpoint return the right thing when this dependency 404s," that's a mock's job. If it's "does my system hold up when this dependency behaves like it does in production, under production-like load," that's virtualization's.
Contract testing: doesn't ask what the response looks like — asks whether it's still true
Contract testing, covered in depth here, answers a question mocking structurally can't: not "what does my code do with this response" but "is what my mock assumes about the real API still what the real API actually does." A consumer writes down exactly what it depends on; the provider's real implementation gets tested against that same expectation. It's the only one of the three that catches drift automatically, because it's specifically testing whether the assumption is still valid — a mock will happily keep returning last year's response shape forever without complaint.
Using the right one for the actual problem
These aren't competing choices where you pick the single "best" one — most teams that do this well use two or three together: a fast mock for the daily loop of building against an endpoint that doesn't exist yet or is annoying to depend on, contract tests to catch the mock quietly going stale, and virtualization reserved for the smaller set of cases where load or multi-step statefulness is actually what's being tested. The mistake isn't using a mock — it's treating a mock's "this passed" as proof of something a mock was never built to prove.
Xerat02
Building MockBase.
More from the blog

400 vs 409 vs 422: Three Ways an API Says "No"
All three mean "I'm not doing that," and all three tempt a tired developer into reaching for whichever one they remember first — but they're answering three different questions about what's actually wrong with the request.

502, 503, 504: Three Codes for Three Different Kinds of Broken
All three mean the server side failed you, but they're describing three different failures — collapsing them into "the API is down" throws away the one clue that tells you where to actually look.