如何忽略 SoapUI 测试用例中的某些测试步骤错误?

How to ignore certain test step errors in SoapUI test case?

目标

我想要 "regular" 测试步骤来破坏 SoapUI 测试用例,而 不同的 测试步骤子集 应该 允许失败.

理由

我有一个 SoapUI 测试用例,它执行相当复杂的功能测试,其中一些可选细节由额外的 JDBC 测试步骤检查。由于这些详细信息是 "optional",即使这些 JDBC 测试中的一项或多项失败,测试用例也不应失败(即它应该变为绿色)。

快到了

如果需求允许测试用例中的所有测试步骤失败,我可以简单地切换测试用例行为:

Open the TestCase Options dialog (from the TestCase toolbar) and uncheck the Abort on Error option. When you run the TestCase that step still fails but SoapUI will continue running through the other TestSteps Functional Tests | Data-Driven Tests (SoapUI.org)

问题

我通过插入两个 Groovy 测试步骤解决了这个问题

  1. 将当前测试用例设置存储在(临时)测试用例自定义 属性 字段中;
  2. 在可选步骤之前转向错误行为;
  3. 在(临时)属性的可选步骤后恢复以前的错误行为。

之前:disableFailOnErrorBehavior.groovy

testRunner.testCase.with {
    // Store current TestCase options in (temporary) TestCase properties.
    setPropertyValue('_failOnError', failOnError.toString())
    setPropertyValue('_failTestCaseOnErrors', failTestCaseOnErrors.toString())
    log.debug "Saved FailOnError behavior: ${failOnError}, ${failTestCaseOnErrors}."

    // Allow following TestSteps to fail without aborting the TestCase immediately.
    setFailOnError(false)
    setFailTestCaseOnErrors(true)
    log.info "Set FailOnError behavior: ${failOnError}, ${failTestCaseOnErrors}."
}

之后:restoreFailOnErrorBehavior.groovy

testRunner.testCase.with{
    // Use (temporary) TestCase properties to restore initial TestCase options.
    setFailOnError(getPropertyValue('_failOnError').toBoolean())
    setFailTestCaseOnErrors(getPropertyValue('_failTestCaseOnErrors').toBoolean())
    log.info "Restored FailOnError behavior: ${failOnError}, ${failTestCaseOnErrors}."

    // Remove (temporary) TestCase properties.
    removeProperty('_failOnError')
    removeProperty('_failTestCaseOnErrors')
    log.debug "Clean up temporary properties: done."
}

这些脚本依赖于两种方法来改变测试用例的行为:

  • 右键单击测试用例;
    Select 选项;在基本选项卡下—— 取消选择“出错时中止”[如果选中]