2

I am using groovy, assertj, junit and gradle. I have a test that contains assertion like that

assertThat(actualLongList).isEqualTo(expectedLongList)

When I run gradle test and those lists are not equal, it generates a test report with an exception like that

org.junit.ComparisonFailure: expected:<...ent2",
"element3",
"element4",
"element5]"]> but was:<...ent2",
"element4,
"element5",
"element6]"]>

Can I somehow configure exception output format so it will fully output both lists?

 org.junit.ComparisonFailure: expected:
<["element1",
"element2",
"element3",
"element3",
"element4",]> but was:,
<["element1",
"element2",
"element4",
"element5",
"element6",]>
Vitalii Vitrenko
  • 9,763
  • 4
  • 43
  • 62

1 Answers1

3

That's how org.junit.ComparisonFailure#getMessage() works (see javadoc). If you want to have a full (better ?) description, you can use containsOnlyElementsOf (or any containsXxxElementsOf you see fit), you will get something like:

java.lang.AssertionError: Expecting: <["element1", "element2", "element3", "element4", "element5", "element6", "element7", "element8", "element9"]> to contain only: <["element1", "element2", "element3", "element4", "element5", "element6", "element7", "element8", "element0"]> elements not found: <["element0"]> and elements not expected: <["element9"]>

Joel Costigliola
  • 6,308
  • 27
  • 35