Forum Discussion

skillsoft's avatar
skillsoft
Frequent Contributor
12 years ago

Fix for hanging issue when assertion fails in teardown?

Hi,

I'm encountering an issue that has been previously reported where the test case hangs if using a teardown script where the assertion fails. If I run the same script as a groovy script step, everything is fine. Any word on when this will be fixed?

http://www.leaderwww.soapui.org/viewtopic.php?t=16472

Thanks,

Mary

6 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Please do not user tear down scripts to make assertions. They are supposed to be used for clean up operations and should not throw Exceptions.

    Using a Groovy test step for such assertions is a much better alternative.

    Regards,

    Renato Athaydes
    SmartBear Sweden
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    Thanks for the reply. Is that documented anywhere? It seems as I'm not the only one to do this...

    I was using it to gather up all the errors in the test case and return it to the calling testcase. I'll see if I can do the same thing with a groovy test step. It seemed that I couldn't before. I'll let you know...

    Thanks,

    Mary
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    If I put the same code in a groovy step it's not returning the failure back to the calling test case. It seems that putting it in the teardown script is the best solution. I've tried using various events as well with no luck. Any suggestions?

    I'm calling a method in a class. The method's code is here (I got it from this forum and modified it a bit):

    def static getErrors(sname,testRunner,log )
    {
    def results = testRunner.results

    log.info( "Checking " + results.size() + " TestStepResults.." )

    def c = 0;
    while( c < results.size() )
    {
    if( results[c].status.toString() == "FAILED" )
    {
    break;

    }
    c++

    }

    // failed?
    if( c < results.size() )
    {

    assert false, "Failure in TestStep [" + results[c].testStep.name + "] for " + sname + " with this message"+results[c].messages
    /*for( msg in results[c].messages )
    {
    //log.info(c+": "+msg )
    assert false, results[c].testStep.name+" failed for "+sname+ " with this message"+ msg
    }
    */

    }


    }
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Mary,

    I'm sorry to hear you're having problems. I tried to reproduce the issue with running your script as a Groovy test step, and I think I know what the problem is. The "Run TestCase" step fails correctly when the target case fails, but it doesn't log the message we want. The reason for this is that a test case, by the default, stops running and fails immediately if one of its test steps fails. Because of this, the Groovy test step at the end is never executed if a previous step fails.

    Luckily, solving this is easy. Go to the target test case and open its options dialog (either right click the TestCase and select "Options" or click the options icon in the TestCase view) and uncheck the "Fail on error" checkbox. Now, the test case will continue running through its steps even after one test step fails, allowing the final Groovy script to run no matter what.

    This should be a more stable way of doing this kind of assertion without having to rely on a TearDown script. I hope this helps, and if not, let me know and I'll happily assist further.

    Regards,

    Arian
    SmartBear Sweden
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    I already have the "fail on error" unchecked. That is not the issue :-). The issue is I'm calling the testcase to run via groovy, not by the Run testcase step. If I was doing the latter, your solution would work which I already know. When I run the code via the teardown script, the testcase/teststep returns the error to the calling test case, but the testcase/teststep NEVER stops running. I have to restart SoapUI. If I run the exact code via a groovy script at the end of the testcase, the error is not returned to the calling testcase, but the testcase/teststep completes. Do you have any other suggestions?

    Thanks,

    Mary
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi again,

    I seem to have misunderstood your problem then - sorry for that. I haven't been able to reproduce this issue yet, so if you could send me a small project where this occurs, that would help.

    Meanwhile, a suggestion for a workaround to avoid using TearDown scripts is to set your TestStep failure message as a property instead using groovy, and then retrieve those properties' values in the calling groovy script. Does this make sense?

    Regards,

    Arian
    SmartBear Sweden