Strategies for Using Test Doubles

Test doubles are like any tool; the bigger challenge is not in learning how to use them but in knowing when to use them. This section describes a few schools of thought and provides some recommendations for appropriate use of test doubles.

Exploring Design

Suppose AddressExtractor does not exist. When you test-drive summaryDescription, you’ll of course recognize the need for logic that takes a JSON response and ultimately returns a formatted string. You could code the entire implementation for that in the PlaceDescriptionService. It’s not much code (a little more than a dozen lines, based on the code in AddressExtractor as it exists).

Some programmers always wear the designer hat, seeking designs that exhibit ...

Get Modern C++ Programming with Test-Driven Development 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.