Forum Discussion

Arah's avatar
Occasional Contributor
3 years ago

Assert if any TestStep failed



how can I assert if any of the TestSteps failed using Groovy Script? I have written a groovy script script that among other things run another TestCase and I want it to assert every TestStep (in called TestCase) if it failed. Currently it check TestSteps but it does not include Groovy Script Steps (Groovy Script steps that have asserts inside of them).

This is what I have so far...




//Get TestStepList from called Project
def assertFinishedStatus = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepList()
//Assert if any step with assertions failed in called TestCase
def moduleStatus = true;
     // check that testStep has assertionStatus 
    // (for example groovy testSteps hasn't this property since
    // there is no asserts on its)
        if(it.assertionStatus == AssertionStatus.FAILED){
   "TestStep: ${}   - - - - - - - - - - - -   Status: FAILED"
            return moduleStatus = false;
        }else if(it.assertionStatus == AssertionStatus.VALID || it.assertionStatus == AssertionStatus.UNKNOWN){
   "TestStep: ${}   - - - - - - - - - - - -   Status: OK!"
            return moduleStatus = true;
assert(moduleStatus != false)





4 Replies

  • nmrao's avatar
    Champion Level 3
    Will not the test step fails when the assertion is failed? why to check if the assertion is failed or not? Trying understand the case.
    • Arah's avatar
      Occasional Contributor

      In TestCase (A) in Groovy Script  TestStep I run another TestCase (B), after that TestCase (C) and so on... In same Groovy Script TestStep that runs another TestCases I want an assertion that causes TestCase(A) failed if any of the TestSteps in TestCases (B,C, ...) failed. The code I pasted does not work for Groovy Script TestSteps in TestCases (B, C, ...) even if there is an assertion inside of them. TestCase (A) just ignores it and run another TestSteps which I want to avoid.

      • richie's avatar
        Community Hero
        Hey Arah,

        I cant help with your groovy (Rao's the fella for that), but id like to highlight that creating tests with dependencies on others (like using the test script library approach used in UI automation) probably isnt the best approach in soapui. Other than setup testcases, i always try and ensure there arent any inter testcase dependencies as this can add complications/complexities that can be difficult to resolve.

        Just my opinion....doesnt mean im actually correct! πŸ˜‰