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.jpg

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

fake.jpg

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

stubs.jpg

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.jpg

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

Recent Posts

Let's Talk About The American Dream

Let's Talk About The American Dream

A few months ago I wrote about what it means to stay gold — to hold on to the best parts of ourselves, our communities, and the American Dream itself. But staying gold isn’t passive. It takes work. It takes action. It takes hard conversations that ask us to confront

By Jeff Atwood ·
Comments
Stay Gold, America

Stay Gold, America

We are at an unprecedented point in American history, and I'm concerned we may lose sight of the American Dream.

By Jeff Atwood ·
Comments
The Great Filter Comes For Us All

The Great Filter Comes For Us All

With a 13 billion year head start on evolution, why haven’t any other forms of life in the universe contacted us by now? (Arrival is a fantastic movie. Watch it, but don’t stop there – read the Story of Your Life novella it was based on for so much

By Jeff Atwood ·
Comments
I Fight For The Users

I Fight For The Users

If you haven’t been able to keep up with my blistering pace of one blog post per year, I don’t blame you. There’s a lot going on right now. It’s a busy time. But let’s pause and take a moment to celebrate that Elon Musk

By Jeff Atwood ·
Comments