【发布时间】:2015-03-24 05:01:32
【问题描述】:
我正在尝试模块化我的测试用例,因此我正在运行一个共享测试用例(作为一个过程),它会做一些有用的事情并返回一个结果值。由于我需要传入非字符串输入属性,我必须从 groovy 运行测试用例:
def findLoopEndTC = testRunner.testCase.testSuite.testCases["TestCase - Find Loop End"]
assert findLoopEndTC != null, "Referred TC not found"
def runContext = new com.eviware.soapui.support.types.StringToObjectMap()
runContext.put("TestStepContext", context)
def runner = findLoopEndTC.run( runContext, false )
assert runner.status != com.eviware.soapui.model.testsuite.TestRunner.Status.FAILED : runner.reason
我了解到测试用例是使用 SINGLETON_AND_WAIT 模式运行的,该模式可确保 TestCase 本身以线程安全的方式运行。 我的问题是如何以线程安全的方式从运行测试用例返回值?
我试过runner.getRunContext().getProperty("Result"),但似乎上下文属性不再存在。所以似乎只有“经典”方式findLoopEndTC.getPropertyValue("Result"),但这显然不是线程安全的。
还有其他可能吗?
我使用免费版的 SoapUI。
【问题讨论】:
-
我选择了这个方案:在runContext中传入一个Map作为参数,并在map中设置返回值:def results = [:]; runContext.put("results", results);
-
不幸的是,我发现从负载测试运行时 tc.run() 方法本身不是线程安全的(这是需要线程保存的主要地方)。因此它仅可用于功能测试。查看我的错误报告forum.soapui.org/…
标签: groovy thread-safety soapui