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 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.