An Introduction to Mock Objects in Ruby

This is a question that gets asked a lot. Mock Objects are most useful in testing a single class in isolation, helping you focus on testing the behaviour of just that one class. That one class is the real implementation not a mock – so not everything is mocked.

However, it’s right to be concerned that these unit tests do not guarantee that the system will behave how you expect. For that you need integration/acceptance tests which don’t use Mock Objects and which check that the real objects collaborate correctly.

I’d suggest it’s best to aim for high test coverage in your unit tests, but focus test coverage in your integration/acceptance tests on critical business scenarios. This is because unit tests run fast and failures in unit tests are more easily diagnosed.