0

我正在使用 groovy、assertj、junit 和 gradle。我有一个包含这样断言的测试

assertThat(actualLongList).isEqualTo(expectedLongList)

当我运行gradle test并且这些列表不相等时,它会生成一个带有异常的测试报告

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

我可以以某种方式配置异常输出格式,以便完全输出两个列表吗?

 org.junit.ComparisonFailure: expected:
<["element1",
"element2",
"element3",
"element3",
"element4",]> but was:,
<["element1",
"element2",
"element4",
"element5",
"element6",]>
4

1 回答 1

1

这就是org.junit.ComparisonFailure#getMessage()工作原理(参见javadoc)。如果你想有一个完整的(更好的?)描述,你可以使用containsOnlyElementsOf(或任何containsXxxElementsOf你认为合适的),你会得到类似的东西:

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"]>

于 2017-07-04T02:59:22.770 回答