O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required