Code Coverage for Mock Objects

Code Coverage for Mock Objects

My team is using a mock object testing tool (Rhino Mocks) for unit testing some methods in our code. The methods that we use mocks for, are not being shown as covered in the final NCover coverage report (we assume because the mock object, not the actual methods are being called).

Is there a way (or even a different mocks tool), we could use that would allow us to utilize mock objects and still be able to see the code coverage for the mocked methods?


RE: Code Coverage for Mock Objects

By default, we exclude mocking frameworks from obtaining coverage since most people don't want to know the coverage of Rino Mocks.

I thought when you mock, you can only mock an interface?

Even so, the real class will never actually be called. The mocking framework will provide a class that looks and feels like the real class but is not the real class. Therefor you will never have coverage on your mocks.

Mocking framework are not meant to be used for code coverage. To answer your question, no other framework will help with your coverage.

Joe Feser


RE: Code Coverage for Mock Objects

Hi Joe,

Thanks for your response... that makes sense to me now. I think we were utilizing mocks at too high of a level. We only wanted to mock certain methods (not all methods) of a class. By utilizing partial mocks, we are now able to write unit tests that result in NCover coverage for all of the class except the intentionally mocked methods.

Thanks again for talking me through this.

Regards, Bobby


RE: Code Coverage for Mock Objects

Glad to hear everything is working.

Feel free to contact us with any questions.

Joe Feser