Definition
What it is
user = User(name="Ana") # the constructor needs an address; the test doesn't
address = DummyAddress() # never read, never called
user.set_address(address)
The dummy is the fifth and least used member of the test double family defined by Gerard Meszaros in xUnit Test Patterns (2007). Its role is narrow: fill a gap in a signature so the code under test can run. It has no behaviour, no expectation, no recorded calls.
If the code under test touches the dummy, that is a signal — either the dummy is not appropriate for this test, or the test is exercising a path it was not designed to exercise. Meszaros' guideline: a dummy that gets used should be reclassified as a stub (if it is returning data) or a mock (if it is verifying a call).
Why it matters
The alternative to a dummy is calling the real constructor with dummy data, which is verbose, brittle (if the constructor changes) and misleading (it suggests the test cares about the address). A dummy makes the intent explicit: "this parameter exists but the test does not touch it".
The cost is a subtle one. A dummy that starts being used becomes a maintenance trap: the test passes because the dummy happens to do what the code expects (usually nothing), and when the code path changes, the test breaks for the wrong reason. Keeping dummies minimal and dead is the discipline; the moment a dummy is read or called, it should be promoted.
How it works
graph LR T[Test] --> S[System under test] T --> D[Dummy] S -.->|if calls| D D -.->|no behaviour| X[Failure or noop] style D fill:#FFF3E0 style X fill:#FFEBEE
The pattern in practice. Minimal interface: the dummy implements the interface with methods that throw "not implemented" or return null — whichever the framework treats as a failure. Single use: created inside the test, not shared, not reused. Visible intent: the variable name (dummyAddress, unusedRepository) states what the test intends.
Test double family
Aspect | Dummy | ||||
|---|---|---|---|---|---|
Purpose | Satisfy signature | Provide canned answer | Record calls | Assert expectations | |
Behaviour | None | Fixed answer | Delegates | Expected only | Real, simplified |
Used in test | No | Yes | Yes | Yes | Yes |
Fails on its own | No | No | No | Yes | No |
Common failures
Origin
The word entered software testing from the broader English usage of "dummy" for a sham or a placeholder (19th century: a "dummy book" on a shelf, a "dummy run"). Meszaros' book codified the five-double taxonomy in 2007 and, in doing so, gave the dummy its own precise definition — distinct from a stub (which returns something) and from a fake (which works). Before the formalisation, developers used "dummy" interchangeably with "stub" and "mock", which is why the term survives in legacy code as an over-broad label.
19th century — "dummy" as a placeholder or sham in general English
2007 — Meszaros formalises Dummy as one of five doubles
2011 — Sinon.js keeps dummies implicit (you pass null, not a dummy class)
2014 — Jest popularises simpler dummies via
{}andnull2020s — Modern test frameworks de-emphasise dummies in favour of explicit stubs
Object Mother is a way to create dummy objects for your tests without having to build them from scratch every time.
— Martin Fowler, *ObjectMother*, 2006 (paraphrase)
Evidence
FAQ
- When should I use a dummy?
When a function requires a parameter the test does not care about. The dummy makes the intent explicit and prevents the test from fabricating irrelevant state.
- Dummy vs stub?
A dummy is never used; a stub is used and returns a fixed answer. The moment the code under test touches the dummy, it becomes a stub (or the test should be redesigned).
- Can I pass `null` instead of a dummy?
Often yes, if the language allows it. But
nulldoes not document intent as clearly as a nameddummyAddressvariable, and languages with strict typing may require an object.- When should I refactor instead of adding another dummy?
When the same constructor or method has required dummies in three or more tests. The fourth is the signal that the signature is too wide; refactor the production code.
Connections
Meszaros, G. (2007). xUnit Test Patterns. https://martinfowler.com/books/meszaros.html
Fowler, M. (2007). Mocks Aren't Stubs. https://martinfowler.com/articles/mocksArentStubs.html
Etymology
Origin: inherited
dummy(noun): from "dumb" (silent, mute); 19th-century sense of "a sham or placeholder"
Semantic network
● broader ● narrower ● related
Used in the garden
Sources
Meszaros, G. (2007). xUnit Test Patterns. https://martinfowler.com/books/meszaros.html
Fowler, M. (2007). Mocks Aren't Stubs. https://martinfowler.com/articles/mocksArentStubs.html