'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

Still have questions?
Connect with us
Thank you.
Your request has been received.
Thank you!
The form has been submitted successfully.