Hosted by:
Unit testing expertise at your fingertips!
Home | Discuss | Lists

Mocks, Fakes, Stubs and Dummies

Are you confused about what someone means when they say "test stub" or "mock object"? Do you sometimes feel that the person you are talking to is using a very different definition? Well, you are not alone!

The terminology around the various kinds of Test Doubles (page X) is confusing and inconsistent. Different authors use different terms to mean the same thing. And sometimes they mean different things by the same term! Ouch! (See the sidebar What's in a (Pattern) Name? (page X) for why I think names are important.)

Part of the reason for writing this book was to try to establish some consistency in the terminology to give people a set of names with clear definitions of what they mean. In this sidebar, I provide a list of the current sources and cross-reference the terminology they use with what I use in this book.

Role Descriptions

Here is a summary of what I mean by each of the major Test Double pattern names:

PatternPurposeHas BehaviorInjects indirect inputs into SUTHandles indirect outputs of SUTValues provided by test(er)Examples
Test DoubleGeneric name for family
Dummy Object (page X)Attribute or Method Parameternono, never calledno, never callednoNull, "Ignored String", new Object()
Test Stub (page X)Verify indirect inputs of SUTyesyesignores theminputs
Test Spy (page X)Verify indirect outputs of SUTyesoptionalcaptures them for later verificationinputs (optional)
Mock Object (page X)Verify indirect outputs of SUTyesoptionalverifies correctness against expectationsoutputs & inputs (optional)
Fake Object (page X)Run (unrunnable) tests (faster)yesnouses themnoneIn-memory database emulator
Temporary Test Stub (see Test Stub)Stand in for procedural code not yet writtenyesnouses themnoneIn-memory database emulator

Terminology Cross-Reference

I'm listing some sources of conflicting definitions just to make it clear what the mapping is to my pattern names:

Sources and Names Used in them
Test Double Double or stand-in
Dummy ObjectStub Dummy Stub
Test StubFakeFakeStubStubDummy MockFake
Test Spy Dummy Spy
Mock ObjectMockMockMockMockMockMockMock
Fake Object Dummy
Temporary Test Stub Stub
OMG's CORBA Stub Stub

Some specific examples from this table are:

The sources quoted in the table above are:

AstelsBook: Test-Driven Development[TDD-APG]Pearson
BeckBook: Test-Driven Development[TDD-BE]Pearson
FeathersBook: Working with Legacy Code[WEwLC]Prentis Hall
FowlerBlog: Mocks are Stubs[MAS]martinfowler.com
jMockPaper: Mock Roles Not Objects [MRNO]ACM (OOPSLA)
UTWJBook: Unit Testing With Java[UTwJ]Morgan Kaufmann
OMGObject Management Group's CORBA specsOMG
PragmaticBook: Pragmatic Unit Testing with Nunit[PUT]Pragmatic Programmers
RecipesBook: JUnit Recipes[MRNO]Wiley
.NetBook: Test-Driven Development in MS .NET[TDD.Net]Microsoft Press

Feedback Requested

I need your feedback! Which names make sense to you? Which ones don't? What would you suggest instead?

Please post any comments on the Yahoo! group created for this purpose:


Page generated at Wed Feb 09 16:38:57 +1100 2011

Copyright © 2003-2008 Gerard Meszaros all rights reserved

All Categories
Introductory Narratives
Web Site Instructions
Code Refactorings
Database Patterns
DfT Patterns
External Patterns
Fixture Setup Patterns
Fixture Teardown Patterns
Front Matter
Result Verification Patterns
Test Double Patterns
Test Organization
Test Refactorings
Test Smells
Test Strategy
Value Patterns
XUnit Basics
xUnit Members
All "Terminology"
Mocks, Fakes, Stubs and Dummies
XUnit Terminology Cross-reference