【发布时间】:2014-03-11 07:13:00
【问题描述】:
SoapUI 项目可以在加载时运行随机脚本。
使用日志和项目变量调用加载脚本。
在我的共享库中,我有方法 - addAsserts() 遍历整个项目并将模式合规性断言添加到 SOAP 测试步骤。在我的加载脚本中,我调用了共享方法
addAsserts(this)
将“this”作为参数传递并在 addAsserts 方法中设置closure.delegate 以使“项目”变量在闭包范围内可访问
addAsserts 方法在 sharedUtil.groovy 中定义:
static def addAsserts(that){
def closure={
project.testSuites.each { testSuiteName, testSuiteObject ->
testSuiteObject.testCases.each { testCaseName, testCaseObject ->
testCaseObject.testSteps.each { testStepName, testStepObject ->
if ("class com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep" == testStepObject.getClass().toString() ) {
log.info "adding 'Schema Compliance' assertion to ${testSuiteName}/${testCaseName}/${testStepName}"
testStepObject.addAssertion('Schema Compliance')
}
}
}
}
}//closure
closure.delegate=that // <--- i would like NOT to pass 'that' as parameter
// but rather detect in runtime with some kind of
// getCallerInstance() method
return closure.call()
}
问题:
是否可以在运行时使用某种 getCallerInstance() 方法检测调用者实例?
【问题讨论】: