O'Reilly logo

Quality Code: Software Testing Principles, Practices, and Patterns by Stephen Vance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cutting the Cord

When you test-drive, you create the seams that support your testing intent. Recognizing that the retrieve() method (Listing 14-2)

• Was a bit long

• Had no ready-made seams with which to sever the network connection for testing

• And performed a wide variety of low-level mechanics in support of its purpose

I decided to simplify and encapsulate it before continuing. Commit [c602d34] was the first application of this principle for WebRetriever.

Listing 14-2: The working but unwieldy and poorly testable first version of WebRetriever.retrieve()

public String retrieve(String URI) throws IOException {  HttpClient httpClient = new DefaultHttpClient();  HttpGet httpGet = new HttpGet(URI);  HttpResponse ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required