'Y'

JUnit 5 – new approach, new functionalities. Part 3

Junit has more assertion type methods than Junit 4. Several have been added and they work very well together with the lambda expressions in Java 8. All these types of methods are static and come from the org.junit.jupiter.api.Assertions class.

Assertions in Junit 5

Junit has more assertion type methods than Junit 4. Several have been added and they work very well together with the lambda expressions in Java 8. All these types of methods are static and come from the org.junit.jupiter.api.Assertions class.

The comparison between assertions in Junit 4 and Junit 5 look like this:

 JUnit 4 JUnit 5 
 Assert Class

The optional message is the first parameter
Assertions Class

The optional message is the last parameter

The assertThat method has been removed

New methods: assertAll and assertThrows


The message in assertions is the last parameter of the methods:

assertions_methods_JUnit5.jpg

The supplier allows for lazy initialization in case of complex messages. A chunk of code which uses possible assertions looks like this:

possible assertions code.jpg
junit5.jpg

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.