以下是通過使用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
這個想法不是一個負載測試,因爲我沒有測試性能,但與我的遺留系統保持一致。所以我從大量的請求中跑出來。 –