Forum Discussion

Awesome's avatar
Awesome
Frequent Contributor
17 years ago

how to abort & fail a running testCase with groovy script

hi all,

with a groovy script i would like to check a preceding property step, if the value is '0' i want to abort & fail the test case.

thanks for the help!

2 Replies

  • Hello,

    You could use assert for it. It will fail and abort test case execution. For example:

    ...
    assert context.testCase.properties["cnt"].value == "0"
    ...


    where cnt is test case property. If its value is different than 0 it will fail..

    Let me know if this helps you,
    robert
  • Awesome's avatar
    Awesome
    Frequent Contributor
    thanks Robert, that worked nicely!

    ---
    for those who are interested, i also found that this works too:
    //Grab number of records returned by sql query
    def nRecordsSql = context.expand( '${NumberOfRecordsReturned#nRecordsSql}' )

    //If number of records returned is '0' then fail.
    if (nRecordsSql == "0"){
    testRunner.fail( "FAILED: the number of records returned by sql was '0', forcing test case abort." )
    com.eviware.soapui.support.UISupport.showInfoMessage( "USER: The number of records returned by sql was '0', forcing test case abort." )
    // throw new Exception( "ABORT: the number of records returned by sql was '0', forcing test case abort." )
    }