您的位置:首页 > 产品设计 > UI/UE

用SoapUI进行Webservice的性能压力测试

2016-03-24 00:00 190 查看

1. 新建测试工程



选择在一个测试用例中测试多个方法,并为测试生成压力测试:



2. 为测试 Step 添加变量:

右键选中 Test Step ,添加一个 Grooy Script Step ;添加一个变量 count 并设置初始值为 0



3. 添加一个随机变量:

右键选中 Test Step ,添加一个 Grooy Script Step ;名称为 rand ,用下面的代码产生一个随机值

[java]
view plain
copy

Random rand = new Random()

result = "test_" + rand.nextInt(100)

4. 使用动态参数:

打开 init 操作的 SOAP 请求,将输入参数用上面步骤产生的随机替换

[xhtml]
view plain
copy

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.test.jastar.com.cn">

<soapenv:Header/>

<soapenv:Body>

<web:run>

<web:in0>${rand#result}</web:in0>

</web:run>

</soapenv:Body>

</soapenv:Envelope>

5. 按条件选择执行操作:

同样的再添加一个 Grooy Script Step ;名称叫 ExecHandler ,用来条件控制用例的执行

[vb]
view plain
copy

def countProps = testRunner.testCase.getTestStepByName("count")

def index = countProps.getPropertyValue("count")

if (index == "0") {

testRunner.runTestStepByName("init")

} else {

testRunner.runTestStepByName("run")

}

countProps.setPropertyValue("count", "1")

6. 执行测试:

打开 LoadTest , disable 掉 init 和 run(ExecHandler 控制 init 和 run 的执行 ) ,设置好参数, OK 可以开始跑了。正如你所预期的 init 方法只执行一次,而 run 将会按照你所设置的方式来执行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息