Chapter 7. Testing in isolation with mock objects

This chapter covers

  • Introducing and demonstrating mock objects

  • Performing different refactorings

  • Using mock objects to verify API contracts on collaborating classes

  • Practicing on an HTTP connection sample application

 

The secret of success is sincerity. Once you can fake that you’ve got it made.

 
 --Jean Giraudoux

Unit-testing each method in isolation from the other methods or the environment is certainly a nice goal. But how do you perform this feat? You saw in chapter 6 how the stubbing technique lets you unit-test portions of code by isolating them from the environment (for example, by stubbing a web server, the filesystem, a database, and so on). But what about fine-grained isolation like being able ...

Get JUnit in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.