Chapter 3. Test doubles

 

In this chapter

  • What can we do with test doubles?
  • What kind of test doubles do we have at our disposal?
  • Guidelines for using test doubles

The concept of stubs or dummies has been around about as long as we’ve had the ability to structure software code into classes and methods. Once the primary reason for creating such utilities was to serve as a placeholder until the real thing became available—to allow you to compile and execute one piece of code before its surrounding pieces were in place.

These objects have much more diverse purposes in the context of modern developer testing. Instead of merely allowing the compilation and execution of code without certain dependencies present, the test-infected programmer creates a variety of such “for testing only” facilities in order to isolate the code under test, speed up test execution, make random behavior deterministic, simulate special conditions, and to give tests access to otherwise hidden information.

These purposes are served by similar and yet different types of objects that we collectively refer to as test doubles.[1]

1 Though the term test double was first introduced to me by fellow Manning author J. B. Rainsberger. I credit Gerard Meszaros and his book, xUnit Test Patterns: Refactoring Test Code (Addison Wesley, 2007), for popularizing the term and the related taxonomy within the software development community.

3.1. The power of a test double

 
 
 

3.2. Types of test doubles

 
 

3.3. Guidelines for using test doubles

 
 

3.4. Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest