soapUI完整基本测试(来自csdn)不要问为什么系列5
用SoapUI进行Webservice的性能压力测试 收藏
1. 新建测试工程
选择在一个测试用例中测试多个方法,并为测试生成压力测试:
2. 为测试 Step 添加变量:
右键选中 Test Step ,添加一个 Grooy Script Step ;添加一个变量 count 并设置初始值为 0
3. 添加一个随机变量:
右键选中 Test Step ,添加一个 Grooy Script Step ;名称为 rand ,用下面的代码产生一个随机值
view plaincopy to clipboardprint?
01.Random rand = new Random()
02.result = "test_" + rand.nextInt(100)
Random rand = new Random()
result = "test_" + rand.nextInt(100)
01.Random rand = new Random()
02.result = "test_" + rand.nextInt(100)
Random rand = new Random()
result = "test_" + rand.nextInt(100)
4. 使用动态参数:
打开 init 操作的 SOAP 请求,将输入参数用上面步骤产生的随机替换
view plaincopy to clipboardprint?
01.<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.test.jastar.com.cn">
02. <soapenv:Header/>
03. <soapenv:Body>
04. <web:run>
05. <web:in0>${rand#result}</web:in0>
06. </web:run>
07. </soapenv:Body>
08.</soapenv:Envelope>
<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>
01.<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.test.jastar.com.cn">
02. <soapenv:Header/>
03. <soapenv:Body>
04. <web:run>
05. <web:in0>${rand#result}</web:in0>
06. </web:run>
07. </soapenv:Body>
08.</soapenv:Envelope>
<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 ,用来条件控制用例的执行
view plaincopy to clipboardprint?
01.def countProps = testRunner.testCase.getTestStepByName("count")
02.def index = countProps.getPropertyValue("count")
03.if (index == "0") {
04. testRunner.runTestStepByName("init")
05.} else {
06. testRunner.runTestStepByName("run")
07.}
08.countProps.setPropertyValue("count", "1")
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")
01.def countProps = testRunner.testCase.getTestStepByName("count")
02.def index = countProps.getPropertyValue("count")
03.if (index == "0") {
04. testRunner.runTestStepByName("init")
05.} else {
06. testRunner.runTestStepByName("run")
07.}
08.countProps.setPropertyValue("count", "1")
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 将会按照你所设置的方式来执行。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述