How to get passed and failed test case count in SoapUI

前端 未结 1 1945
无人共我
无人共我 2021-01-14 07:35

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

相关标签:
1条回答
  • 2021-01-14 08:30

    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:

    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,

    0 讨论(0)
提交回复
热议问题