Coding Horror

programming and human factors

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.

Written by Jeff Atwood

Indoor enthusiast. Co-founder of Stack Overflow and Discourse. Disclaimer: I have no idea what I'm talking about. Find me here: https://infosec.exchange/@codinghorror