I'm pretty comfortable with the core concepts of Outside In (especially from this question). However one thing eludes me concerning the mocks you created at each level which then lead to creating the real implementation that the solution requires...

Do you keep using the mocks in the higher-level (outside) tests, and then create another suite of Integration Tests that check all of the production components are working as expected?

Or do you gradually replace the mocks in the higher-level (outside) tests with the working production components and then throw the mocks away?

1 Answer 1


Keep the mocks

While the mocks happen to allow testing before the production components are written, that isn't the only reason to use them.

Mocks give you explicit control over their behavior.

For any injected object whose sibling production object is stateful or relies upon an external system (like a disk drive, database, etc.), it is far easier to control the mocked object's behavior. In some cases, it may even be the only way to make the object return consistent, exact values (e.g., an object which returns the current time versus a mock which can return a pre-specified time).

Keeping the mocks in your tests forces the test object to remain loosely-coupled.

If your tests started using the production objects directly, there is little stopping someone from modifying the tested object to rely on those concrete types. This, in turn, makes it much easier for a lazy maintainer to update the tested object in a way which makes it more difficult in the future to swap out the dependency later.

  • Good, well-explained answer.
    – thehowler
    Oct 22, 2015 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.