Test Doubles: A Taxonomy of Pretend Objects

I wanted to show a co-worker the funny Ping video game from a previous post, but I nearly had a panic attack when the “Fake” picture popped onto his screen. I think your blog is excellent, and I appreciate the feminine form as much as any man, but PLEASE don’t put things on your site that might get me fired.

Jesus. it’s a pair of covered tits. It’s not like you are browsing pr0n. If you get fired for that small amount of skin above you should be glad to be out and not working for such an uptight employer.

Maybe you shouldn’t be reading Coding Horror at work anyway. That’s why they call it “work” and not “play time”.

Haven’t you read the “study” showing that people who read tech blogs are more productive and better programmers (or whatever it is we do)?

Perfect justification for reading blogs at work, I’d say. It’s “professional development.”

Regarding cland’s comment:

The category is “testing doubles” or “substitutes”, not “stubs”.
I agree with the taxonomy completely, but would propose one more:

Sometimes your test double derives from the actual object under test.
I propose calling these “self mocks”, “self stubs”, etc.

In general when you find yourself doing this it indicates other problems in your code. However, it is sometimes necessary for the purposes of making something visible, or for overriding methods to substitute only part of the object.

it’s funny how terms take hold. it’s unfortunate in some sense.

for instance, the term ‘stub’ barely has any semantic relevance. at best it would be as a receipt of transaction which we could take to mean recording the method calls, but this is becoming known as a test ‘spy’. or is it that the stub stands in for the check? honestly i haven’t slightest why ‘stub’ was every the selected term.

then there is the english meaning of ‘mock’ which really conveys nothing about verification, but only the idea of something that pretends to be something else. in that sense all test doubles are mocks, even if ever so scantily. left to my intuition i’d expect a mock to be what dave mann called a ‘self mock’. and for mock, something like ‘appraiser’ --you know, someone with a checklist, seems more fitting.

is it valuable to use terms with general meanings more akin to a specialized use? i think so. it saves brain cells. unfortunately I think we love out DD-style realm building too much to actually do so.

Seriously. Covered or not, I’m yet another person who reads this blog at work and would have a hard time explaining that one off.

Elf/Vulcan ears or cat-eye contacts or an obvious toupee or an obvious nose-job – anything else would be more SFW.

Just another $0.02. Thanks for the (in general) all around fantastic blog. :slight_smile:

Thanks for the taxonomy. It certainly clarifies what (some) people mean when they talk about such things.

I do not feel a day-to-day need to make such fine distinctions between dummy, fake, stub and mock objects - I know what I need when I need it - but I applaud you for doing it for me.

Frankly, I rarely find the need to make such fine distinctions between the different types of “testing” objects identified but it will make reading Mr Fowler’s articles a lot clearer.

Many thanks.

;[;][;ju87uy