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.
The comparison between assertions in Junit 4 and Junit 5 look like this:
|JUnit 4||JUnit 5|
The optional message is the first parameter
The optional message is the last parameter
The assertThat method has been removedNew methods: assertAll and assertThrows
The message in assertions is the last parameter of the methods:
The supplier allows for lazy initialization in case of complex messages. A chunk of code which uses possible assertions looks like this:
Interested in JUnit? Check out our trainings.
Java and Web Technologies Expert