如何在并行运行的不同SoapUI测试用例实例中获取单独的上下文? [英] How to get a separate context in different SoapUI testcase instances running in parallel?
问题描述
我有一个使用Groovy脚本测试步骤的SoapUI测试用例(名称create entity
),该步骤使用上下文中接收的一些变量,计数器值,处理它并返回一些其他值,例如returnId
//这些变量在不同的线程之间有效共享,我想避免它
def threadId = context。 getProperty(threadId)
def counter = context.getProperty(counter)。toInteger()
...
testRunner.testCase.setPropertyValue(returnId,returnId)
此测试用例从另一个测试用例groovy脚本步骤调用,该步骤创建了多个测试用例执行的线程
...
def counter = new AtomicInteger()
...
//多线程
1.upto(2){
线程<<新线程({
def tc = testRunner.testCase.testSuite.getTestCaseByName(create entity)
def txInstanceContext = new com.eviware.soapui.support.types.StringToObjectMap()
/ /线程特定参数
def threadId = ...
txInstanceContext.put(threadId,threadId)
//多次执行循环
1.upto(2 ){
def number = counter.getAndIncrement()。toString()
//执行特定变量
txInstanceContext.put(counter,number)
log.info开始上传+ number +at+ new Date()。getTime()
def runner = tc.run(txInstanceContext,false)
while(runner.status == Status.RUNNING){
this.sleep(50)
}
log.info状态:+ runner.status +,上传所需的时间为:+ runner.timeTaken +ms
...
assert runner.status!= Status.FAILED:runner.reason
def returnId = t c.getPropertyValue(returnId)
log.infoFinished uploading+ number +at+ new Date()。getTime()
log.infoReturned id:+ returnId
})
}
threads.each {
it.start()
}
threads.each {
it.join()
}
如何为每次执行获得一个独立的范围,以避免由其他线程执行重写/设置测试用例变量?
我认为你需要创建一个TC runner,然后创建 WsdlTestRunContext
。
我遇到类似的情况,我需要创建一个TC跑步者。 在这里。我相信你可以更进一步,通过使用 WsdlTestCaseRunner
的 createContext(StringToObjectMap properties)
方法创建一个上下文。
I have a SoapUI test case (name "create entity"
) with groovy script test step which uses some variables received in context, e.g. counter value, processes it and returns some other value, e.g. returnId
// these variables are effectively shared across different threads, I want to avoid it
def threadId = context.getProperty("threadId")
def counter = context.getProperty("counter").toInteger()
...
testRunner.testCase.setPropertyValue("returnId", returnId)
And this test case is called from another test case groovy script step, which creates several threads with numerous test case executions
...
def counter = new AtomicInteger()
...
// multiple threads
1.upto(2) {
threads << new Thread({
def tc = testRunner.testCase.testSuite.getTestCaseByName("create entity")
def txInstanceContext = new com.eviware.soapui.support.types.StringToObjectMap()
// thread specific parameter
def threadId = ...
txInstanceContext.put("threadId", threadId)
// multiple executions loop
1.upto(2) {
def number = counter.getAndIncrement().toString()
// execution specific variable
txInstanceContext.put("counter", number)
log.info "Started uploading " + number + " at " + new Date().getTime()
def runner = tc.run( txInstanceContext, false )
while(runner.status == Status.RUNNING) {
this.sleep(50)
}
log.info "Status: " + runner.status + ", time taken for upload was: " + runner.timeTaken + " ms"
...
assert runner.status != Status.FAILED : runner.reason
def returnId = tc.getPropertyValue("returnId")
log.info "Finished uploading " + number + " at " + new Date().getTime()
log.info "Returned id: " + returnId
...
}
})
}
threads.each {
it.start()
}
threads.each {
it.join()
}
How to get an isolated scope for each execution, to avoid overriding/setting test case variables by other thread executions?
I think you need to create a TC runner and then WsdlTestRunContext
.
I ran into similar situation where I needed to create a TC runner. Here . I believe you can go one step further and create a context by using createContext(StringToObjectMap properties)
method of this WsdlTestCaseRunner
.
这篇关于如何在并行运行的不同SoapUI测试用例实例中获取单独的上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!