AssertJ记录断言的结果 [英] AssertJ to log assertion's results

查看:186
本文介绍了AssertJ记录断言的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解是否可以将AssertJ配置为在不中断运行比较的路由的情况下将断言的否定结果记录到文件中.

I'm trying to understand if is possible to configure AssertJ to log the negative result of an assertion to a file without interrupting the routing that is running the comparison.

此请求背后的原因是,我们正在比较两个软件版本生成的JSON以发现差异,但我不想手动创建所有检查,而是希望利用AssertJ中已经可用的功能.

The reason behind this request is that we are comparing the JSON generated by two version of a software to spot differences, but instead of manually creating all the checks I would like to leverage the functionalities already available in AssertJ.

作为一种可能的解决方案,我正在考虑对断言异常使用try/catch,但我确实担心例程的整体性能.

As a possible solution to this I was thinking of using a try/catch for assertion exceptions, but I'm really concerned about the overall performance of the routine.

有什么主意吗?

推荐答案

您可以通过捕获AssertionError来访问错误消息,然后使用任何日志记录框架. 如果要捕获所有错误(并且不会在第一个错误上失败),请使用软断言.

You can access the error message by catching the AssertionError, then use whatever logging framework. If you want to capture all the errors (and not fail at the first one), use soft assertions.

这篇关于AssertJ记录断言的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆