我可以保留 Groovy 电源断言并仍然打印自定义消息吗?

Can I keep the Groovy power assert and still have a custom message printed?

我使用 Katalon Studio 进行测试自动化。它带有内置脚本编辑器 (Groovy)。

所以,我可以使用 Groovy 的 power assert,当断言失败时,它会给我一个漂亮而详细的输出消息。

但是,其他一些非技术人员(或技术水平较低的人员)希望自己 运行 进行自动化测试。他们的问题是他们无法正确解释失败消息。

我知道我可以使用 assert expression1 : expression2 来打印自定义消息,但我真的更喜欢 power assert 输出。

有没有办法让同时自定义消息和断言消息?

复制自 https://sqa.stackexchange.com/questions/34217/can-i-keep-the-groovy-power-assert-and-still-have-a-custom-message-printed

您可以将消息作为字符串添加到您的断言中:

assert "a custom message" && expression

由于非空字符串在 Groovy 中为真,断言只会失败 – 并产生输出 – 如果表达式为假 + 您将从中获得强大的断言输出。