Mate Mrše
Mate Mrše

Reputation: 8414

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

I use Katalon Studio for my test automation. It comes with an in-built script editor (Groovy).

So, I can use Groovy's power assert that gives me a nice and detailed output message when the assert fails.

However, some other non-technical (or less-technical) staff would like to run automated tests themselves. And their problem is they are unable to correctly interpret the fail message.

I know I can use assert expression1 : expression2 for printing the custom message, but I really prefer the power assert output.

Is there a way to have both custom message and power assert message?

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

Upvotes: 1

Views: 373

Answers (1)

Michael
Michael

Reputation: 2683

You could just add the message as a String to your assertion:

assert "a custom message" && expression

Since a non-empty String is truthy in Groovy, the assertion will only fail –and produce output– if the expression is falsey + you'll get power assertion output from it.

Upvotes: 1

Related Questions