如何从SOAP UI TestSuite Teardown脚本获取测试运行断言结果(状态和名称)?

时间:2015-11-06 15:45:04

标签: testing groovy soapui

我无法从SOAP UI中的testsuite拆卸级别的测试步骤中获取断言结果。我查看了Javadoc并试图使用getAssertionList()但是调用它会导致错误。到目前为止,这是我的Groovy脚本:

def failedTestCases = 0
def successTestCases = 0
def failedTestSteps = 0
def successTestSteps = 0

runner.results.each { testCaseResult ->
    def caseName = testCaseResult.testCase.name
        def caseStatus = testCaseResult.status.toString()
        if(caseStatus == 'FAILED'){failedTestCases ++}
     else {successTestCases ++}

     log.info "Test Case: $caseName $caseStatus" 

     testCaseResult.results.each{ testStepResults ->
        testStepResults.messages.each() { msg -> log.info msg }
        def stepName = testStepResults.testStep.name
        def stepStatus =  testStepResults.status.toString()
        if(stepStatus == 'FAILED'){failedTestSteps ++}
        else{successTestSteps ++}

        log.info "Test Step: $stepName $stepStatus"

        def testStep = testStepResults.testStep
        log.info "XX" + testStep.name
        testStep.getAssertionList().each{
            log.info "$it.label - $it.status"   
        }
    }
}

log.info "Total test cases:" + (successTestCases + failedTestCases).toString()
log.info "Total succeeded: $successTestCases"
log.info "Total failed: $failedTestCases"
log.info "Total test step count:" + (successTestSteps + failedTestSteps).toString()
log.info "Total succeeded: $successTestSteps"
log.info "Total failed: $failedTestSteps"

我能够看到XX [TestStepName],但没有来自日志条目的断言或结果,但我收到此错误:

Fri Nov 06 10:13:36 EST 2015:ERROR:发生错误[没有方法签名:com.eviware.soapui.impl.wsdl.teststeps.WsdlPropertiesTestStep.getAssertionList()适用于参数类型:()值:[]],有关详细信息,请参阅错误日志

1 个答案:

答案 0 :(得分:0)

对于SOAP UI测试步骤,步骤的类型很重要。我并不熟悉SOAP UI api,但有些测试用例似乎不支持getAssertionList()调用。所以我们在得到断言之前检查测试类型,这看起来效果很好。

这是我的最终剧本。似乎运作良好。现在,我可以获得本地报告的测试用例,测试步骤和断言。我正在使用SOAP UI免费版,所以我将使用它来输出XML报告。

def failedTestCases = 0
def successTestCases = 0
def failedTestSteps = 0
def successTestSteps = 0
def failedAssertions = 0
def successAssertions = 0

runner.results.each { testCaseResult ->
    def caseName = testCaseResult.testCase.name
        def caseStatus = testCaseResult.status.toString()
        if(caseStatus == 'FAILED'){failedTestCases ++}
     else {successTestCases ++}

     log.info "Test Case: $caseName $caseStatus" 

     testCaseResult.results.each{ testStepResults ->
        testStepResults.messages.each() { msg -> log.info msg }
        def stepName = testStepResults.testStep.name
        def stepStatus =  testStepResults.status.toString()
        if(stepStatus == 'FAILED'){failedTestSteps ++}
        else{successTestSteps ++}

        log.info "Test Step: $stepName $stepStatus"

          //Some test steps don't have assertions, so calling getAssertionList() blows up
          //We want WSDLTestStep (request)
        if (testStepResults.testStep.config.type == 'request')
        {
            testStepResults.testStep.getAssertionList().each{
                def assertLabel = it.label
                def assertStatus = it.status
                if (assertStatus == 'VALID') { successAssertions ++ }
                else {failedAssertions ++ }
                    log.info "$it.label - $it.status"   
            }
        }
    }
}

log.info "Total test case count:" + (successTestCases + failedTestCases).toString()
log.info "Total test cases succeeded: $successTestCases"
log.info "Total test cases failed: $failedTestCases"

log.info "Total test step count:" + (successTestSteps + failedTestSteps).toString()
log.info "Total test steps succeeded: $successTestSteps"
log.info "Total test steps failed: $failedTestSteps"

log.info "Total test assertion count:" + (successAssertions + failedAssertions).toString()
log.info "Total test assertions succeeded: $successAssertions"
log.info "Total test assertions failed: $failedAssertions"