如何在SoapUI中传递和失败的测试用例计数

Uda*_*aik 3 groovy soapui

我想知道我的测试套件中失败和通过的测试用例的总数

我知道我们可以通过获取testCases的总数testRunner.testCase.testSuite.getTestCaseCount().

我想知道有没有办法让我们从testRunner获得所需的东西.

alb*_*iff 6

在SOAPUI文档中,您可以看到以下脚本.您可以tearDown Script使用tearDown scripttestSuite视图的选项卡将代码作为TestSuite 的代码:

在此输入图像描述

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 }
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

此脚本记录每个testCase的名称,如果testCase失败,则显示断言失败的消息.

一个更加时髦的脚本完全相同并且还计算testCase失败的总数可能是:

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"
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你,

  • 谢谢你的答案,但我想要一个没有任何拆解脚本的解决方案.我通过使用套件参数做了一些解决方法.因为,这个答案是完美的,标记为正确 (2认同)