Skip to content

FAQ

Frequent questions: when to use a dummy, how it differs from a stub, and when to refactor instead.

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.