DevPrep

All topics › Software testing

Test doubles: dummy, stub, spy, mock, fake — what's the difference?

Middle PRO

Essence

A test double is any object that stands in for a real dependency in a test (Gerard Meszaros's term). The five kinds differ in what they do with calls:

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store