如何对来自 AssertJ 的异常消息进行分组以获得更好的报告?

How to group exception messages from AssertJ for better reporting?

起初,我们使用 TestNG Asserts 进行所有自动化测试验证,它可以抛出预定义的错误消息。魅力报告根据错误消息对失败进行分组,使其非常易于阅读和理解。

最近我们开始使用 AssertJ 来执行我们的测试验证。这是一个很棒的框架,但它会抛出很长的异常消息(有更多信息)。问题是现在我的魅力报告无法将所有这些失败归为一类,因此单独报告它们很难阅读。

我知道我们可以覆盖 AssetJ 错误消息,但我不知道如何为我的自定义 class 对象字段验证做这件事。请指导我。谢谢。

为了更简单地表达我的问题,我当前的异常消息如下

UnrecognizedPropertyException: Unrecognized field "type" (class com.data.files.Files), not marked as ignorable (4 known properties: "name", "hash", "id", "versionId"]) at [Source: {"id":"2yI94ibmVPI","name":"File01.html","versionId":"xzmnggrX6iQ","hash":"39252a3c0577a4d28da144b414871264","type":"FILE"}; line: 1, column: 1190] (through reference chain: com.data.files.Files["type"])

但我需要的只是下面的消息(剩余信息可以是堆栈跟踪的一部分)

UnrecognizedPropertyException: Unrecognized field "type" (class com.data.files.Files)

实现此目标的最简单方法是什么?

您可以使用 QAF which provides webelement specific assertion and verification aka checkpoint. If there is unexpected exception, in report you will find summary. It also reports each checkpoint with automatic capture screenshot on failure with meaningful message along with error analysis。另一个好处是使用 assertion/verification 你不需要等待 QAF 自动处理它。

在 AssertJ 中没有简单的方法来减少错误消息,它们是在框架中烘焙的。