Verify the Exception Payload

We can generalize the idea of verifying the exception message. In the last section, we made a deliberate decision to temporarily ignore the cause of the exception, the other of the two attributes that could help us distinguish why the exception was thrown. We could have used the cause as an alternative means of verification or even to supplement our verification. In fact, the message and cause are the only user-settable attributes2 of the Throwable class, the base class for exceptions of all types3 in Java. Throwable closely resembles the base class of exception hierarchies in other languages and frameworks. For example, C# has the System.Exception class that has InnerException and Message attributes. C++ has only ...

Get Quality Code: Software Testing Principles, Practices, and Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.