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

Verify the Exception Type

As we showed in Chapter 8, the object-oriented testing frameworks make it easy to verify that a particular type of exception is thrown. Oftentimes, this is sufficient to determine the correctness of our code. Many methods only throw a single exception or only have a single error handling code path that requires testing.

The code in Listing 11-1 typifies a unified exception handling strategy in which errors are wrapped in an application-specific exception tailored to the context.

Listing 11-1: A typical unified exception handling strategy

public class SomeClass {  public void doSomething() throws ServiceFailureException {    try {      makeNetworkRequest();    } catch (RemoteException rexp) ...

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