After

In this chapter you learned the important technique of introducing stubs and mocks to emulate behavior of dependent objects. Your tests don’t have to interact with live services, files, databases, and other troublesome dependencies! You also learned how to use a tool to simplify your effort in creating and injecting mocks.

You’ve focused on making sure the production code is clean and well-designed in this and the prior two chapters. Doing so will extend the life of your system. However, the bigger design picture isn’t complete without also continually refactoring your tests. You’ll focus on some test cleanup in the next chapter.

Get Pragmatic Unit Testing in Java 8 with JUnit now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.