Forum Discussion

Teltstra_Corpor's avatar
Occasional Contributor
13 years ago

Continue Assertions in Groovy Step when one assertion fails

We are using SoapUI Pro with Test Cases where we write assertions inside Groovy Steps.

Test Step: Groovy Script Step

//Assertion 1
def ProductOfferingCode = context.expand(...something...)
assert ProductOfferingCode == 'something'

//Assertion 2
def productOfferingSource = context.expand(...something...)
assert productOfferingSource == 'something'

//Assertion 3
def isSubscription = context.expand(...something...)
assert isSubscription == 'something'

When Assertion 1 fails, SoapUI Pro will "Exit" the Groovy Step, and go to next step in Test Case.

How can I force SoapUI to continue with Assertion 2 and Assertion 3, even when Assertion 1 fails.

Also, I already know about the "Abort on Error" option, which continues to the next step when one step fails. But what I need is to continue with other assertions in the same Groovy step.

Jatin Kumar

4 Replies

  • SmartBear_Suppo's avatar
    SmartBear Alumni (Retired)

    in groovy
    assert ProductOfferingCode == 'something' throws AssertionException so the flow of the script ends there.

    Here is the simple tweak

    def assertionList = []
    //Assertion 1
    def ProductOfferingCode = context.expand(...something...)
    ProductOfferingCode == 'something' ? "Assertion1 pass" : assertionList.add("Assertion1 fails")

    //Assertion 2
    def productOfferingSource = context.expand(...something...)
    productOfferingSource == 'something' ? "Assertion2 pass" : assertionList.add("Assertion2 fails")

    //Assertion 3
    def isSubscription = context.expand(...something...)
    isSubscription == 'something' ? "Assertion3 pass" : assertionList.add("Assertion3 fails")

    assert assertionList.isEmpty() : assertionList.toString()

    So you can add which assertions failed and if there is something in assertionList it means that somethig failed.

    Hope this helps

    SmartBEar Software
    • Gkm's avatar

      It is not working for me , Got compilation error

    • Gkm's avatar

      Once again thank you so much nmrao :smileyhappy:

      Your comments solved my problem,

      def error = []
      if (jsonid != dbid) {error.add("jsonid : $jsonid is not equal to dbid: $dbid")}
      if (jsonname != dbname) {error.add("jsonname : $jsonname is not equal to dbname: $dbname")}
      assert error.size() == 0," $error " 
      if(error.size() == 0){ "Script Passed" }