Working with the JUnit built-in assert approach
Starting with a short assertion definition recap, this section will give you an overview of JUnit's built-in verification mechanism. Advancing the example, we'll be confronted with more complex assertions and recognize how they impair readability. But we'll learn how to improve them by means of assertion test helpers. Finally, we'll discuss a few limitations of this approach.
Understanding the basics
By now, you comprehend why unit tests are usually arranged in phases. And it's clear that the outcome verification takes place in the third phase. The technical mechanism to achieve this is based on assertions. In principle, assertions check whether a Boolean predicate evaluates to true or false. In the event of the value false
, an AssertionError
is thrown. The runtime tool captures these errors and reports them as failures. As you already know, tests taking this approach are denoted as self-checking.
JUnit provides a built-in assertion utility, the...