Test Doubles: A Taxonomy of Pretend Objects

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

This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2007/01/test-doubles-a-taxonomy-of-pretend-objects.html

Admit it, you just wanted to post a picture of boobies.

Marcus, I use mocks almost exclusively when writing my unit tests because if you attempt to have the thing you are unit testing use actual objects it quickly becomes a (complicated) systems test instead. Mocks can also let you do some tests that are otherwise hard-to-impossible to test, such as asserting that your object under unit test only makes some call once (this is useful where that call is possibly long-running or state-modifying in some way that is hard to test).

If I’m not mistaken, I believe that picture comes from the Victoria’s Secret catalog. October 2005 edition. Page 27.

And boobies dominate over ood stuff. I’m confident about fate of this world :).


As i understand it, mock objects are usually used in unit testing situations: a unit test should have as few dependencies as possible, ideally it should only depend on the object/method that is being tested.

The issue is that objects are very often dependent on one another (composed with other objects, …), and your unit tests therefore end up testing what you want to test, but also every object in the composition hierarchy of what you want to test.

Mock objects are used to remove this composition hierarchy by composing the tested object with mock objects, therefore removing all dependencies, and allowing you to test only what you want to test, and nothing else.

They look to me like they’re ready for production.

Marcus, it is good to take a look at the original mock objects paper too: (pdf) http://www.connextra.com/aboutUs/mockobjects.pdf. As I understand them, mock objects are like little spies that can be inserted into other objects to check whether they are being used as intended. They also have the good property of breaking dependencies and can also work as stubs providing canned data.

Great picture choices. Insert here appropriate or inappropriate witty remark here about the silicone twins.

I really love the choice for ‘mock’. 1) It’s a perfect choice. I really can’t think of anything that would have been as good. 2) I’m an avid Lewis Carroll and John Tenniel fan and love seeing the Alice artwork get recognition.

Mock, dummy, fake … what is this. Name your stub category day? They all STUBS. Why make it more confusing?

Look I just created a dummy object that morphs into a fake when stubed in my fake test…

I was hopping to pop over here and make some clever comment about the imagery used in this post. However, it looks like any sophmoric quip I could have come up with has already been covered. Excellent job, gents.

had a hard time explaining to my female co-worker at office that I was reading a technical blog. Thanks.

I’m with dinah. It filled my heart with joy to see the mock turtle.

What I want to know is what is that piece of hay/grass sticking down in the boob shot on the right? It looks like the lady has something in her mouth and you cropped it all out. If you haven’t done any cropping then it is a complete mystery as to why this would be there in the first place. Please elaborate!

Caprice Bourret. I’d recognize those anywhere.

Matt, I’m pretty sure that’s a strand of hair, not hay/grass.

It was difficult to come up with a better image choice for “Fake”. “Mock”, on the other hand, is incredibly difficult.

I never really understood what the whole “mocking” business is all about. Why not just implement the objects to begin with?

How hard was it to find a picture of boobs that actually had something covering them?

Thanks for the pointers you guys!