JUnit 5 – new approach, new functionalities. Part 4
Assumptions in Junit 5
Junit Jupiter offers many of the assumption type methods from Junit 4. Junit Jupiter also adds methods that function together with the lambda expressions in Java 8. All assumption methods from Junit Jupiter are static and come from the org.junit.jupiter.api.Assumptions class. The message parameter is on the last position.
Assertions type methods are executed just in the cases where assumptions are accomplished.
The method looks like this:
A comparison between assumptions in Junit 4 and Junit 5 looks like this.
Assumptions
JUnit 4 |
JUnit 5
|
Assume class |
Assumptions class
assumeNotNull and assumeNoException methods have been removed |
Using an assume type method can look like this:
Conclusions
Junit 5 offers a new and flexible API for writing tests for assertions and assumptions. A lot of methods are offered, static and those adapted to the new functional programming facilities introduced by Java 8. In addition, the new modular architecture facilitates both the developers work as well as the interaction with IDE and other tools.