Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
QA interview question
ProgrammingJuniorCommonTheory

What is the difference between a dummy, stub, spy, mock and fake?

Answer

They are all test doubles, but they serve different purposes. A dummy only fills a parameter, a stub returns configured answers, a spy records calls, a mock carries interaction expectations, and a fake is a lightweight working implementation such as an in-memory repository. Library terminology varies, so explain the behavior you need instead of relying only on the label.

Strong answer includes

  • uses test double as the umbrella term
  • distinguishes state setup from interaction verification
  • notes that framework terminology can differ

Practical example

In a Mockito-based suite, a candidate stubs a payment gateway with when(gateway.charge(any())).thenReturn(success) to drive a happy-path branch, but then adds an unnecessary verify(gateway).charge(...), turning a stub into an accidental mock and making the test fail on any harmless refactor of the call order.

#test-doubles#unit-testing#sdet

Sources

Use test doubles in AndroidGoogle · Definitions, selection and limitations of dummies, stubs, spies, mocks and fakes