在SoapUI中,我准备了TestCase(选项 - 生成数据),包括三个测试步骤:
在这个测试中,我想在同一时间内仅运行两次第三步(这就是为什么我不使用LoadTest)并验证获得的结果 - 它们应该是不同的。为此,我写了一个简单的脚本,如下所示。
def testData = testRunner.testCase.getTestStepByName("Properties");
class MyThread extends Thread {
def i;
def testData;
MyThread(def i, def testData) {
this.i = i;
this.testData = testData;
}
void run() {
generateData();
}
void generateData() {
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def testCaseStep = testRunner.testCase.testSuite.testCases["Options - generate data"];
def soapStep = testCaseStep.testSteps["Generate"];
soapStep.run(testRunner, context);
def xmlResponse = groovyUtils.getXmlHolder("Generate#response")
def responseData = xmlResponse.getNodeValues("//ns2:getResponse/ns2:response");
def row = "row" + this.i;
this.testData.setPropertyValue(row, responseData.toString());
}
}
MyThread thread1 = new MyThread(0, testData);
MyThread thread2 = new MyThread(1, testData);
thread1.start();
thread2.start();
while ((thread1.isAlive() && thread2.isAlive())) {
def data1 = testData.getPropertyValue("row0");
def data2 = testData.getPropertyValue("row1");
assert data1 != data2;
}
不幸的是,这段代码没有正常工作 - 我没有任何错误,但SOAP请求没有启动,新的变量没有创建,断言失败。
你能告诉我为了获得这个测试的好结果有什么必要吗?
我将非常感谢任何帮助。
答案 0 :(得分:0)
代码中修复了一些事情:
context
用于方法,但不可用固定代码:
def testData = context.testCase.getTestStepByName("Properties")
class MyThread extends Thread {
def threadId
def testData
def context
MyThread(def i, def testData, def context) {
threadId = i
this.testData = testData
this.context = context
}
void run() {
generateData()
}
void generateData() {
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def soapStep = context.testCase.testSteps["Generate"]
soapStep.run(context.testRunner, context)
def xmlResponse = groovyUtils.getXmlHolder("Generate#response")
def responseData = xmlResponse.getNodeValues("//ns2:getResponse/ns2:response")
testData.setPropertyValue("row${threadId}" as String, responseData.toString())
}
}
MyThread thread1 = new MyThread(0, testData, context)
MyThread thread2 = new MyThread(1, testData, context)
thread1.start()
thread1.join()
thread2.start()
thread2.join()
while ((thread1.isAlive() && thread2.isAlive())) {
def data1 = thread1.testData.getPropertyValue(thread1.threadId)
def data2 = thread2.testData.getPropertyValue(thread2.threadId)
assert data1 != data2
}