Unit Test More Efficiently with Mock Object Alternatives
Tuesday, December 14th, 2004Here’s an excerpt of my newest articleUnit Test More Efficiently with Mock Object Alternatives, published on DevX.com:
The mock-object testing pattern has commonly been used to test an individual unit of code without testing its dependencies. While this pattern works well for interaction-based testing, it can be overkill for state-based testing. Learn how to streamline your unit-testing using stubs and the pseudo-objects testing pattern.
When you’re unit testing, you often want to test an individual unit of code without testing its dependencies. One common solution to this problem is to utilize the mock-object testing pattern. Though the mock-objects pattern can lead to a great working solution, many times, it is simply overkill. Extreme Programming (XP) espouses the principle: do the simplest thing that could possibly work. To this end, mock objects aren’t always the simplest thing possible. This article introduces you to an approach for testing with stubs using a pattern called “pseudo objects.”