When to use partial mocks

mocking

I'm starting to get comfortable with the idea of fakes, stubs, mocks, and dynamic mocks. But I am still a little iffy in my understanding of when to use partial mocks.

It would seem that if you're planning on mocking a service and need to resort to a partial mock then it is a sign of bad design. Is it that partial mocks are mostly for getting legacy code under test coverage?

On the flip side of this, say I am testing a class which has a Reset() method. If I have already confirmed in a separate test that the Reset() method works, and I have some functionality of the class that should end with a call to this method, is it poor test design to do a partial mock of the object and run tests against the partial mock, defining an Expectation on the Reset() method.

I currently have several tests set up in this manner, is this sort of thing going to get me in trouble later on?

Best Answer

Its good design, imho. What happens when somebody comes after you and changes your method, removing the call to Reset? (btw, why so much state in your objects?) You might never know they screwed up until you hit production. By mocking it and asserting on that method call, you can assure nobody is going to mess up while maintaining your code.