Test Doubles: A Taxonomy of Pretend Objects

Ned recently pointed out Martin Fowler’s article Mocks Aren’t Stubs.

The vocabulary for talking about [pretend objects] soon gets messy – all sorts of words are used: stub, mock, fake, dummy. For this article I’m going to follow the vocabulary of Gerard Meszaros’s upcoming book. It’s not what everyone uses, but I think it’s a good vocabulary and since it's my essay I get to pick which words to use. Meszaros uses the term Test Double as the generic term for any kind of pretend object used in place of a real object for testing purposes.

Personally, I like to think of them as Stunt Objects. Meszaros, via Fowler, defines the following taxonomy of pretend objects:

Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.

Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production.

Stub objects provide canned answers to calls made during the test, usually not responding at all to anything outside what’s programmed in for the test.

Mock objects are pre-programmed with expectations which form a specification of the calls they are expected to receive.

Jeff Atwood

Written by Jeff Atwood

Indoor enthusiast. Co-founder of Stack Overflow, Discourse, and RGMII. Disclaimer: I have no idea what I'm talking about. Let's be kind to each other. Find me https://infosec.exchange/@codinghorror

⏲️ Busy signing you up.

❗ Something's gone wrong. Please try again.

✅ Success! Check your inbox (and your spam folder, just in case).

Recent Posts

An interactive TWiT Series You're the hero of the story! Choose from 1,024 possible endings. OFF by ONE with Jeff Atwood Hosted by Leo Laporte "every choice changes everything!"

Every Choice Changes Everything: The Show

About 3 weeks ago, Leo Laporte and I recorded the first episode of what will be a new monthly show on the TWiT network. Naming things is hard, and we almost voted on the name, like we did for Stack Overflow, but we quickly landed on Off By One with

By Jeff Atwood ·
Comments
Thank You For Being a Friend

Thank You For Being a Friend

It's been one of those months, and by that, I mean one of the 663 months since I was born. This won't be a long post, because I only have two things to say. First, I'm really glad we re-ordered the GMI (Guaranteed

By Jeff Atwood ·
Comments
map of the United States via rgmii.org showing all 3,143 counties by rural (gold) / metro (grey) and population

Launching The Rural Guaranteed Minimum Income Initiative

It's been a year since I invited Americans to join us in a pledge to Share the American Dream: 1. Support organizations you feel are effectively helping those most in need across America right now. 2. Within the next five years, also contribute public dedications of time or

By Jeff Atwood ·
Comments
I’m feeling unlucky... 🎲   See All Posts