Chapter 3Using Test Doubles
You can test a lot of your system using the information you’ve learned over the prior two chapters. But not all units are going to be similarly easy to test.
It’s a safe bet you find your own system hard to test. Perhaps you think the first two chapters made it look too easy. “It must be nice to have a system that supports writing unit tests out of the box, but it doesn’t match my reality,” says Joe.
In this chapter, you’ll learn how to employ test doubles to break dependencies on pain-inducing collaborators. A test double is a stand-in (think “stunt double”) for the dependencies that make your code hard to test. You’re probably already familiar with the name of one kind of test double—a mock object.
With test doubles, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access