Dummy Object
A test double passed around to fill parameter lists but never actually used, serving only to satisfy method signatures or constructor requirements.
Also known as: Dummy, Dummy Parameter, Dummy Objects
Category: Software Development
Tags: testing, software-engineering, patterns, quality
Explanation
A dummy object is the simplest type of test double. It is an object that is passed to the code under test but is never actually used in any meaningful way. Dummies exist solely to satisfy parameter lists, constructor requirements, or interface contracts when the test does not care about that particular dependency.
Consider a function that requires three parameters but your test only exercises logic related to the first one. The second and third parameters still need values to make the code compile and run, but their content is irrelevant. Dummy objects fill these slots. They might be null values, empty objects, default-constructed instances, or any value that satisfies the type system.
Dummies differ from other test doubles in that they are not expected to be called or interacted with. If the code under test does attempt to use a dummy in a meaningful way, it typically results in an error, which actually serves as a useful signal that the test's assumptions about dependency usage are wrong.
In languages with strong type systems, dummies are particularly common. A method might require a Logger, a Configuration, and a Database, but if the test only exercises pure computation, the Logger and Database parameters can be dummies. Some developers create dedicated dummy implementations that throw exceptions on any method call, making it explicit that the object should not be used.
In practice, many developers use null or default values as dummies without thinking of them as a specific test double category. Meszaros's categorization makes the concept explicit, helping teams communicate about testing intent. When a developer sees a null being passed in a test, understanding it as a 'dummy' conveys that the dependency is intentionally irrelevant to this test case.
Modern mocking frameworks can generate dummies automatically. For example, Mockito's default behavior creates a dummy-like object that returns sensible defaults (null for objects, 0 for numbers, empty collections) without any explicit setup.
Related Concepts
← Back to all concepts