如何使用 logger 通过断言打印消息
我正在尝试在我的存储库中实现记录器,但在使用 Junit 实现记录器时遇到一些问题。
示例断言:
logger.info("Asserting the response.");
assertThat(response.statusCode())
.withFailMessage("The test failed with status code:" + response.statusCode())
.isEqualTo(200);
我想使用 logger.error() 函数代替 withFailMessage 但我似乎找不到任何方法。
I am trying to implement a logger in my repo and I am having some issues with implementing logger with Junit.
Sample assertion:
logger.info("Asserting the response.");
assertThat(response.statusCode())
.withFailMessage("The test failed with status code:" + response.statusCode())
.isEqualTo(200);
I want to use logger.error() function in place of withFailMessage but I can't seem to find any method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标准断言(即,
assertthat()
)的意思是立即使用assertionError
失败。如果您想在发生故障时具有自定义逻辑, soft soft sostertions 与“ noreflow noreferrer”> callback功能可能是您要寻找的东西。
您的示例将变成类似:
Standard assertions (i.e.,
assertThat()
) are meant to fail immediately with anAssertionError
.If you would like to have custom logic in case of failures, Soft Assertions together with the callback feature might be what you are looking for.
Your example would become something like: