Group of assertions

An important Jupiter assertion is assertAll. This method allows to group different assertions at the same time. In a grouped assertion, all assertions are always executed, and any failures will be reported together.

The method assertAll accepts a vargargs of lambda expressions (Executable…) or a stream of those (Stream<Executable>). Optionally, the first parameter of assertAll can be a String message aimed to label the assertion group.

Let’s see an example. In the following test, we are grouping a couple of assertEquals using lambda expressions:

package io.github.bonigarcia;import static org.junit.jupiter.api.Assertions.assertAll;import static org.junit.jupiter.api.Assertions.assertEquals;import org.junit.jupiter.api.Test; ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.