Chapter 3. Test doubles
In this chapter
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.