Monday 8 January 2007 — This is 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
Add a comment: