Forum Discussion

alibaba82's avatar
alibaba82
Super Contributor
16 years ago

testcase status via groovy

I have trying to get the status of all test cases after a test suite finishes

testsuite code.

for (i in 0..testSuite.testCaseList.size()-1)
{
def testCase = testSuite.getTestCaseAt(i)
log.info(testCase.getLabel() )
        log.info(testaCase status)

       
}

how can I output the status of the test case here
log.info(testaCase status)

5 Replies

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

    Unfortunately there is no such property as TestCase status.
    What you could try is going through each TestStep of a TestCase and check it's assertionStatus if it is assertable. The groovy script could look something like this :


    for(testCase in testSuite.testCaseList) {
    def failed = false
    for(testStep in testCase.testStepList) {
      if( testStep instanceof com.eviware.soapui.model.testsuite.Assertable && testStep.assertionStatus.toString() != "VALID" ) {
      failed = true
      break;
      }
    }
    if( failed ) log.info testCase.toString() + " FAILURE!"
    else log.info testCase.toString() + " SUCCESS!"
    }


    Regards,

    /Dragica
    eviware.com
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Ali,

    Here 's a new suggestion for you.

    1) in the setup script of the TestSuite, put an empty list in the context for holding the different TestCase runners
    context.runners = []


    2) in the tearDown script of each TestCase, put that TestCases' runner in this list
    context.runners.add( testRunner )


    3) in the tearDown script of the TestSuite, go through the list of collected runners
    for( runner in context.runners )
          log.info runner.status


    This solution is far better since it works on all TestStep types regardless if they are assertabe or not.

    Regards
    /Dragica
    eviware.com
    • lanaandsam's avatar
      lanaandsam
      Occasional Visitor

      Just a quick one... How would one add the name to the runner.status ?

  • alibaba82's avatar
    alibaba82
    Super Contributor
    If I already have hundreds of testcases, is there an easier way to put the teardown script of each testcase without going to each test case manually.

    can this be somehow done at the project load script ?

    Also, what is the reason for the API not to be able to expose testcase stautus for tests cases that are in the testsuite.

    Thanks

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

    I totally agree that this is awkward, the upcoming version will have better API's for this as you request. If you don't want to modify hundreds of testcases you could instead create a TestRunListener extension (as described at http://www.soapui.org/architecture/extensions.html) that puts the testRunner in the context variable in the afterRun event.

    sorry for the hassle.

    regards!

    /Ole
    eviware.com