Test lifecycle

As we saw in Chapter 1Retrospective on software quality and Java testing, a unit test case is composed of four stages:

  1. Setup (optional): First, the test initializes the test fixture (before the picture of the SUT).
  2. Exercise: Second, the test interacts with the SUT, getting some outcome from it as a result.
  3. Verify: Third, the outcome from the system under test is compared to the expected value using one or several assertions (also known as predicates). As a result, a test verdict is created.
  4. Teardown (optional): Finally, the test releases the test fixture to put the SUT back into the initial state.

In JUnit 4, there were different annotations to control these test phases. JUnit 5 follows the same approach, that is, Java ...

Get Mastering Software Testing with JUnit 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.