Skip to content

Dummy

A dummy is a test double that is passed to a piece of code to satisfy its signature but is never actually used; if it is used, the test fails, because the object was never meant to be called.

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

Stub

Spy

Mock

Fake

Purpose

Satisfy signature

Provide canned answer

Record calls

Assert expectations

Working substitute

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.

  1. 19th century — "dummy" as a placeholder or sham in general English

  2. 2007 — Meszaros formalises Dummy as one of five doubles

  3. 2011 — Sinon.js keeps dummies implicit (you pass null, not a dummy class)

  4. 2014 — Jest popularises simpler dummies via {} and null

  5. 2020s — 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)
2007 · Meszaros formaliza Dummy como uno de cinco dobles
5 · doblesdummy, stub, spy, mock, fake
0 · comportamiento esperado de un dummy
1 · propósitosatisfacer la firma

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 null does not document intent as clearly as a named dummyAddress variable, 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

Etymology

Origin: inherited

  • dummy (noun): from "dumb" (silent, mute); 19th-century sense of "a sham or placeholder"

Semantic network

DummyTest doublsoftware-tStubSpyFakeMockTest doubl

● broader ● narrower ● related

Broader

Related

Used in the garden

Sources