Test Double

Noun · Development

Definitions

  1. A generic term for any object that stands in for a real dependency in tests. Types: dummy (passed but never used), stub (returns canned answers), spy (records calls for later assertion), mock (pre-programmed with expectations), and fake (working implementation with shortcuts, like an in-memory database). Term coined by Gerard Meszaros.

    In plain English: A stand-in for a real service or object used during testing — like a stunt double for your code's dependencies.

    Example: "Use a fake SMTP server in tests — it accepts emails and stores them in memory, so you can assert the email content without sending real mail."

Etymology

1999
The concept of substituting objects in tests was common but lacked unified terminology. Various patterns (mock, stub, fake) were used inconsistently across communities.
2000
The term 'mock object' was popularized by Tim Mackinnon, Steve Freeman, and Philip Craig at XP2000, establishing mocking as a core test technique.
2004
Gerard Meszaros coined 'test double' in his book 'xUnit Test Patterns' as an umbrella term covering mocks, stubs, fakes, spies, and dummies, borrowing from the film industry's 'stunt double.'
2010s
Test double terminology became standard in software engineering education. Frameworks like Mockito, Sinon.js, and unittest.mock made test doubles accessible across languages.

Origin Story

The Stunt Double for Software Under Test

A test double is any object or component used in place of a real dependency during automated testing, much like a stunt double standing in for an actor during dangerous scenes. The term was coined by Gerard Meszaros in his 2007 book 'xUnit Test Patterns: Refactoring Test Code,' where he wanted a single umbrella term for the various substitution techniques that testing practitioners had been using for years under inconsistent names. Before Meszaros, developers loosely referred to 'mocks,' 'stubs,' 'fakes,' and 'dummies,' often conflating their meanings. His taxonomy brought clarity: a dummy is passed around but never used, a stub provides canned responses, a spy records interactions, a mock verifies expected behavior, and a fake has a working but simplified implementation. This vocabulary became essential to discussions of test-driven development and clean architecture. By giving the community a shared language, Meszaros helped developers communicate more precisely about testing strategies and make better decisions about when to isolate components versus test them together.

Coined by: Gerard Meszaros

Context: Introduced in the 2007 book 'xUnit Test Patterns' to unify terminology for mock objects, stubs, fakes, and dummies.

Fun fact: Martin Fowler popularized Meszaros's taxonomy in a widely shared 2007 blog post titled 'Mocks Aren't Stubs,' which became one of the most referenced articles in the testing community and helped establish the distinctions as industry standard.

Related Terms