以下是通过使用groovy步骤可以完成的方式。
定义一个测试用例两个测试步骤:
- 测试请求步骤(肥皂,你所示)
- Groovy脚本步骤(这是我所建议的附加一个)
定义如下三个测试用例级别自定义属性像你需要的最小和最大次数它应该重复执行,并提供测试值并保持CURRENT_VALUE
与相同这是一次性工作。因为每次测试运行时,每次都会增加CURRENT_VALUE
,并且不希望更改MIN_VALUE
。这样,每次执行测试用例后都不要重置该值。
- MIN_VALUE
- MAX_VALUE
- CURRENT_VALUE
注意,这不能运行的各个步骤,即,测试用例有顺序执行,以满足您的需要,因为它有重复号时间,希望对你有好处。
在测试请求中,需要使用当前值的占位符。
变化:<req:number>XPTO</req:number>
为:<req:number>${#TestCase#CURRENT_VALUE}</req:number>
下面是Groovy脚本代码:
//Read the test case level properties as integers
def min = context.testCase.getPropertyValue('MIN_VALUE') as Integer
def max = context.testCase.getPropertyValue('MAX_VALUE') as Integer
//Get the previous step name
def pStepName = context.testCase.testStepList[context.currentStepIndex-1].name
//min+1, because already test request is executed once
((min+1)..max).each {
//update the current value incremented by 1
context.testCase.setPropertyValue('CURRENT_VALUE', it.toString())
log.info "Running step ${pStepName} for ${it} time"
//run the previous test step
testRunner.runTestStepByName(pStepName)
}
//finally resetting current value to min value as test finishes
context.testCase.setPropertyValue('CURRENT_VALUE', min.toString())
这Groovy脚本一步基本上采用运行n-1
倍的第一步小心,因为step 1
已在groovy脚本测试步骤之前执行,其中n
是需要执行的总次数(n = max - min
)。
如前所述,只需运行测试用例即可。
来源
2016-03-22 14:43:10
Rao
你可以使用负载测试吗? – Rao
这个想法不是一个负载测试,因为我没有测试性能,但与我的遗留系统保持一致。所以我从大量的请求中跑出来。 –