AssertJ to log assertion's results

巧了我就是萌 提交于 2019-12-24 20:07:00

问题


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.

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.

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.

Any idea?


回答1:


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.




回答2:


If we spoke about any logging frameworks:

  1. we can use File LoggingAppender
  2. set log level for ERROR or WARN
  3. define TestClass or Pacakge for reduce unnecessary messages


来源:https://stackoverflow.com/questions/47638360/assertj-to-log-assertions-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!