Do not fold comparison results for SoftAssertions in console

Answered

Hello,

 

I'm using org.assertj.core.api.SoftAssertions that performs multiple checks per test and prints all results at the end, e.g. for

final SoftAssertions softAssertions = new SoftAssertions();
final String testString = "a test string";
softAssertions.assertThat(testString).as("String has size 1").hasSize(1);
softAssertions.assertThat(testString).as("String has size 2").hasSize(2);
softAssertions.assertAll();

result will be

org.assertj.core.api.SoftAssertionError: 
The following 2 assertions failed:
1) [String has size 1]
Expected size:<1> but was:<13> in:
<"a test string">
at MyTestClass.testName_NonEquals(MyTestClass.java:134)
2) [String has size 2]
Expected size:<2> but was:<13> in:
<"a test string">
at MyTestClass.testName_NonEquals(MyTestClass.java:135)


at org.assertj.core.api.SoftAssertions.assertAll(SoftAssertions.java:133)
at com.example.MyTestClass.testName_NonEquals(MyTestClass.java:136)
...

Note that there are both reference to final assertions call (MyTestClass.java:136) and references to each failure (MyTestClass.java:134, MyTestClass.java:135), so I can easily go to exact failure.

 

But if there will be checks for equal, like 

final SoftAssertions softAssertions = new SoftAssertions();
softAssertions.assertThat("a test string").as("String is 'xxx'").isEqualTo("xxx");
softAssertions.assertThat("a test string").as("String is 'zzz'").isEqualTo("zzz");
softAssertions.assertAll();

then the result will be folded to '<Click to see difference>' link:

org.assertj.core.api.SoftAssertionError: 
The following 2 assertions failed:
1) [String is 'xxx'] <Click to see difference>


at org.assertj.core.api.SoftAssertions.assertAll(SoftAssertions.java:133)
at com.example.MyTestClass.testName_Explicit(MyTestClass.java:130)
...

and no possibility to go to exact failure. If I will click on the link 'Click to see difference', then a new window will be opened with something like this:



Expected

"[xxx]"> but was:<"[a test string]">
at MyTestClass.testName_Explicit(MyTestClass.java:128) expected:<"[xxx]"> but was:<"[a test string]">
2) [String is 'zzz'] expected:<"[zzz]"> but was:<"[a test string]">
at MyTestClass.testName_Explicit(MyTestClass.java:129) expected:<"[zzz]"

 

Actual

"[a test string]"

 

And references to the test class lines are not clickable anymore.

 

So is it possible to prevent the replacing of test results [for soft assertions] to the difference viewer?

 

IntelliJ IDEA 2018.1.4

Build #IU-181.5087.20

0
2 comments
Avatar
Yaroslav Bedrov

Hello Dmitry,

I reported an issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-193318. Please follow it for updates.

 

0
Avatar
Permanently deleted user

Hello Yaroslav,

 

Thank you!

0

Please sign in to leave a comment.