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

Spy Craft

In a way, the wrong turn helped me. Injecting a mock could have been an effective testing technique, but it would also couple the test to the implementation more tightly through the use of an internal type. This is the biggest danger in testing with mocks: the degree of coupling they introduce. [7f74b88] introduces a nicely uncoupled test, shown in Listing 14-4.

Listing 14-4: An implementation-independent test for the behavior of defaulting the protocol to HTTP

@Testpublic void testRetrieveResponse_DomainOnly()    throws IOException {  WebRetriever sut = new WebRetriever();  HttpResponse response =    sut.retrieveResponse("www.example.com");  assertThat(response, is(notNullValue()));}

The concept behind ...

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