Assertions

As we know, the general structure of a test case is composed of four stages: setup, exercise, verify, and tear down. The actual test happens during the second and third stage, when the test logic interacts with the system under test, getting some kind of outcome from it. This outcome is compared with the expected result in the verify stage. In this stage, we find what we call assertions. In this section, we take a closer look at them.

An assertion (also known as a predicate) is a boolean statement typically used to reason about software correctness. From a technical point of view, an assertion is composed of three parts (see the image after the list):

  1. First, we find the expected value, which comes from what we call test oracles. A test oracle is a reliable source of expected outputs, for example, the system specification.
  2. Second, we find the real outcome, which comes from the exercise stage made by the test against the SUT.
  1. Finally, these two values are compared using some logic comparator. This comparison can be done in many different ways, for example, we can compare the object identity (equals or not), the magnitude (higher or lower value), and so on. As a result, we obtain a test verdict, which, in the end, is going to define if the test has succeeded or failed.
Schematic view of an assertion
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.32.67