Monday, June 25, 2007

Mock objects

So I'm reading through the documentation for EasyMock, largely on the recommendation of Neal Ford, Jared Richardson, and others at the recently concluded NFJS.

My principal objection to mock objects has been that they tend to test implementation instead of results. And having read through the 2.2 Readme I think my concern is still justified. I see plenty of ways to verify that methods have been called on the mocked object, but I don't see any way to check the mocked object's state. What if the mocked object changes its interface? This guarantees the test breaks. On the other hand, a state-based test would only be looking at the mocked object's resultant state. The only thing that would break the unit test is if the state accessors changed.

I can certainly see where EasyMock would be helpful. But it still doesn't strike me as a cure-all for the unit testing blues.