Chapter 12. Test Doubles

In Chapter 9, “Dependencies,” we learned how to expose and pass around collaborators to make dependencies explicit and break them. It’s perfectly natural that program elements, most notably objects, somehow depend on each other, but such relations have to be controllable. In this chapter, the subject will be revisited and explored in greater detail. Dependencies can be controlled in several ways, depending on what part they play in a test. Sometimes collaborating objects should be ignored, which may not be as easy as it sounds. Sometimes they’re of paramount importance and must be surveilled with utmost scrutiny.

Test double1 is a general term for an object that replaces a collaborator. Different kinds of test doubles ...

Get Developer Testing: Building Quality into Software 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.