来自 assertJ 的方法 anySatisfy 吞下了实际的失败消息

Method anySatisfy from assertJ swallows actual failure message

我在我的项目中使用 assertJ 来很好地制定测试断言。 我在一个集合上调用 anySatisfy,在该集合中我在一个 lambda 中传递断言,必须满足至少一个集合元素。

assertThat(myCollection).anySatisfy(myCollectionElement-> { 
    assertThat(myCollectionElement).callAnyAssertionMethod();
    assertThat(myCollectionElement).anotherAssertionMethod();
}

一旦没有元素满足要求的断言,anySatisfy 将按预期失败。

问题是控制台输出如下

java.lang.AssertionError: 
Expecting any element of:
  <allCollectionElementsArSerializedHere>
to satisfy the given assertions requirements but none did.

at myPackage.myTestClass.myTestMethod(MyTestClass.java:xyz)

结论我确实知道 anySatisfy 在行 xyz 中被调用失败,但我不知道 lambda 中的哪些特定断言没有得到满足。我只能在调试器中看到它。

如何才能获得预期的日志输出?

你不能,但我们改进了 allSatisfy 以报告未满足的要求。 我们将为下一个版本的 anySatisfy 做同样的事情,我已经创建了 https://github.com/joel-costigliola/assertj-core/issues/1400 来跟踪这个。