JUnit 5 Architecture. Part 5

In this fifth article in our series we look at the CustomStatement class. Happy reading.

CustomStatement class.JPG

Into listing 7, we do the following:
  1. We declare our CustomStatement class that extends the Statement class (1).
  2. We keep references to a Statement field and to a Description field (2) and we use them as arguments of the constructor (3).
  3. We override the inherited evaluate method and call base.evaluate() inside it (4).

JUnit4CustomRuleTester class.JPG

Into listing 8, we use the previously defined CustomRule by doing the following:
  • We declare a public CustomRule field and we annotate it with @Rule (1).
  • We create the myCustomRuleTest method and annotate it with @Test (2).

The result of the execution of this test is shown in figure 1. The effective execution of the test is surrounded by the additional messages provided into the evaluate method of the CustomStatement class.

execution of JUnit4CustomRuleTester.png

Figure 4 The result of the execution of JUnit4CustomRuleTester.

Interested in Java? Check out our trainings.

Catalin Tudose
Java and Web Technologies Expert

Share the knowledge

Luxoft Warsaw - Warsaw Spire, plac Europejski 1, 00-844 Warszawa
Dimitrie Pompeiu nr 5-7 , building C, Et. 5, sect 2, Bucharest, 014459

Contact phone:

021 371 4858
Luxoft Poland Wroclaw - Silver Tower pl. Konstytucji 3-go Maja 3 50-048 Wroclaw
Aleja Generała Tadeusza Bora-Komorowskiego 25, Quattro Business Park Five, 31-476 Kraków, Poland

Contact phone:

+48 122110650
Thank you.
Your request has been received.