Uday Naik
Uday Naik

Reputation: 53

How to get passed and failed test case count in SoapUI

I want to know the total number of failed and passed test cases in my test suite

I know we can fetch total number of testCases by testRunner.testCase.testSuite.getTestCaseCount().

I want to know is there a way so that we can get the required thing from testRunner.

Upvotes: 3

Views: 4874

Answers (1)

albciff
albciff

Reputation: 18507

In SOAPUI documentation here you can see the follow script. You can put the code as a tearDown Script of your TestSuite using the tearDown script tab of your testSuite view:

enter image description here

for ( testCaseResult in runner.results )
{
   testCaseName = testCaseResult.getTestCase().name
   log.info testCaseName
   if ( testCaseResult.getStatus().toString() == 'FAILED' )
   {
      log.info "$testCaseName has failed"
      for ( testStepResult in testCaseResult.getResults() )
      {
         testStepResult.messages.each() { msg -> log.info msg }
      }
   }
}

This script logs the name of each testCase, and in case that the testCase fail show the assertion failed messages.

A more groovier script to do exactly the same and also counts the total number of testCase failed could be:

def failedTestCases = 0

runner.results.each { testCaseResult ->
    def name = testCaseResult.testCase.name
    if(testCaseResult.status.toString() == 'FAILED'){
        failedTestCases ++
        log.info "$name has failed"
        testCaseResult.results.each{ testStepResults ->
            testStepResults.messages.each() { msg -> log.info msg } 
        }
    }else{
        log.info "$name works correctly"
    }
}

log.info "total failed: $failedTestCases"

Hope it helps,

Upvotes: 6

Related Questions