Skip to content
Advertisement

How to show all the failures in Junit Assertions

My requirement is to show all the failures after Junit test run.

I tried two things:

Assertions.assertEquals –> This stops the execution after first failure, and in test report I see only first failure.

JavaScript

assertj.SoftAssertions –> Here execution happens but in test report I do not see any failure message.

JavaScript

Any Idea if any other type of assertion or any other option I can use with these assertions?

I tried Junit5 assertAll

JavaScript

But here it shows failures only for first row, not for all the rows.

Thanks in advance !!!

Advertisement

Answer

JUnit 5 added assertAll:

JavaScript

It takes any number of lambdas, and if I recall correctly each lambda can even throw exceptions. That means you can delegate to methods:

JavaScript

Edit: using assertAll inside assertAll, made difficult because of the index:

JavaScript

The mapToObj may need a cast to Execution, perhaps extracted to another method.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement