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

Error Injection

We can use injection to introduce the data of our choice for testing our software but we can also use it to force error conditions. Although best practice suggests that we keep our methods as small and as simple as possible, there are many times when the tradeoff against design complexity leads to a little more complexity in a method. Consider the hypothetical code to retrieve a response with a proprietary network protocol shown in Listing 8-6.

Listing 8-6: Typical management of connection-oriented protocol in Java

public class NetRetriever {  public NetRetriever() {  }  public Response retrieveResponseFor(Request request)      throws RetrievalException {    try {      openConnection();      return ...

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