5.3 Test Doubles
You can avoid being blocked, in any of these cases, by employing a test double . A test double is a stand-in—a doppelgänger (literally: “double walker”)—for a production class. HTTP giving you trouble? Create a test double HTTP implementation! The job of the test double will be to support the needs of the test. When a client sends a GET request to the HTTP object, the test double can return a canned response. The test itself determines the response that the test double should return.
Imagine you are on the hook to build the service but you aren’t concerned with unit testing it (perhaps you plan on writing an integration test). You have access to some classes that you can readily reuse.
-
CurlHttp, which uses cURL[15] to make ...
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