QA Engineer Interview Question

What is the difference between a mock, a stub, and a fake, and when do you use a real dependency instead?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

A stub returns canned responses so the code under test can proceed. A mock also records interactions so you can assert they happened, verifying behavior rather than state. A fake is a lightweight working implementation, like an in memory repository. Use real dependencies when the integration itself is the risk, and test doubles when the dependency is slow, costly, or hard to force into a specific state.

Why interviewers ask this

The terms get used interchangeably, so precise definitions signal depth. More importantly, the interviewer wants your judgment about when a double is the wrong call, since over mocking produces tests that pass happily while the system is broken. Naming containerized real dependencies for integration tests shows you know the modern middle option rather than treating it as mock everything or nothing.

How to structure your answer

  • Define all three crisply, one line each.
  • Explain state verification versus interaction verification.
  • Give the case where a real dependency is the right choice.
  • Warn about over mocking and tests that only test the mocks.
  • Mention containers for realistic integration dependencies.

Example answer

Spoken example, first person

A stub is passive, it just returns whatever you told it to return so the code can keep going. A mock is a stub that also remembers what happened to it, so you can assert the payment service was called exactly once with these arguments. A fake is a real but simplified implementation, like an in memory version of a repository, which behaves properly but is not production grade. The distinction that matters in practice is that stubs and fakes support state verification, asserting on the outcome, while mocks support interaction verification, asserting on the conversation. I lean toward the former, because asserting on interactions couples the test to implementation details, and then a refactor breaks a hundred tests without a single behavior changing. Where I use real dependencies is anywhere the integration is the risk. If the question is whether our query actually works against Postgres, a mocked database answers nothing, so I run the real thing in a container. That is my default for the integration layer now, since containers made it cheap. I mock third party services I do not control, then back that with scheduled contract tests against their sandbox.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • What is a sign that a test suite is over mocked?
  • How would you test error handling for a third party you cannot force to fail?
  • When is a spy the right tool rather than a full mock?

Related qa engineer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot