Assertions and Exceptions



Definition

Assertions and exceptions testing is a black-box unit testing technique for embedding tests within classes.

Discussion

What oracle do you use to know the expected behavior of an object? The requirements of the application are at much too high of a level of abstraction. A single requirement is implemented by many collaborating classes, and a single class collaborates with others to help implement many requirements. The class comment is still at too high of a level of abstraction, is potentially vague, and is typically not testable. Even the class responsibilities are usually not specific enough to be testable because they are implemented by multiple methods. Class method signatures are even more specific, but the operation name, parameter names, and parameter types only give the blackbox interface and syntax of the method, not its intended semantic meaning. Looking at the method body only provides the “as coded” semantics, which may include defects, but not the intended semantics.

The answer to these questions is given by:

Objectives

The typical objectives of assertions and exceptions testing are to:

Preconditions

Assertions and exceptions testing can typically begin when the following preconditions hold:

Completion Criteria

Assertions and exceptions testing is typically complete if the following postconditions hold:

Steps

During assertions and exceptions testing, unit testers typically perform the following steps:

Work Products

Assertions and exceptions testing typically results in the following work products:

Limitations

Assertion and exception testing typically is subject to the following limitations:

Guidelines