3.3. Guidelines for using test doubles

Test doubles are the programmer’s tools, just like hammers and nails are for a carpenter. There are appropriate ways to bang a nail with a hammer and there are less appropriate ways—and it’s good to be able to identify which is which.

Let’s start with what I consider perhaps the most important guideline to keep in mind when you’re about to reach for a test double—picking up the right tool from your toolbox.

3.3.1. Pick the right double for the test

There are many kinds of test doubles to choose from and they all seem to be slightly different. What are their sweet spots, and which one should we choose?

There’s no hard and fast rule for much of this stuff, but in general you should probably mix and match a ...

Get Effective Unit Testing now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.