Forum Discussion

SLuong's avatar
SLuong
Contributor
15 years ago

[RESOLVED]Script Assertions custom message

Is there a way to show a custom error message when an assert fails in Script Assertions?

5 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    does the standard

    assert 1 == 0 : "BAD THING HAPPENED"

    syntax work?

    regards!

    /Ole
    eviware.com
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Well, this works in a Groovy script step:

    [tt:1rvkimgz]import org.codehaus.groovy.transform.powerassert.PowerAssertionError

    try {
    assert 1==0
    } catch (PowerAssertionError pae) {
    throw new PowerAssertionError("BAD THING HAPPENED")
    }[/tt:1rvkimgz]
  • That will work. Wish there is an easier way since I have a lot of asserts 
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Doh! Is it really that simple?

    Ahhh, not quite perfect. You still get the expression that way:
  • Well at least we know now.  Actually the Try/Catch block is working well for me.  Thanks McDonald