'Y'

JUnit 5 new approach, new functionalities. Part 4

The last article in our series on JUnit 5 and its new functionalities. Hope you enjoyed the first three articles.

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:

accomplished assumptions JUnit5.jpg

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:

assume type method JUnit5.jpg

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.

Interested in JUnit? 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
Success
Thank you.
Your request has been received.