XUnit patterns

Monday 8 January 2007This is almost 18 years old. Be careful.

Martin Fowler has updated his Mocks Aren’t Stubs article. It looks like a good introduction to a deep understanding of mock object testing. I was particularly struck by the definitions of dummy, fake, stub, and mock 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.
  • Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what’s programmed in for the test.
  • Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive.

I’d never heard this distinction, but it is a good one. Fowler attributes it to Gerard Meszaro, who it turns out is writing a book about patterns within test development, xUnit Patterns. The whole book is available on the website (for now), and looks like a good compendium of practices and ideas in test development.

I continue to work on how to best incorporate testing into real-world projects. The pressure of time, and the complexity of large systems, both conspire to make testing a real challenge. So I’ll be looking through the xUnit Patterns to see what it can add to my understanding.

Comments

[gravatar]
Yeah, it's nice to have a clear distinction between categories of "unreal" objects, some of them I had never heard of before, even though I thought I knew what the name meant. For small projects or projects where I have a clear specification, I usually do a lot of testing at first. If the project is short enough, I may actually have complete testing. But if it goes on too long, I begin to get too lazy to update my tests or make new ones, and then I write code which invalidates my old tests, and it ends up making the whole thing useless :/ I will definitely be taking a look at that book!

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.