今天我们来讲解如何用JMeter实现接口功能、性能测试。
内容:
-
JMeter实现接口功能测试
-
JMeter实现接口的性能测试
JMeter实现接口功能测试
企业性能测试编写脚本过程:接口功能测试脚本调试通过--->脚本优化(性能测试脚本)。
接口脚本调试
-
新增货品接口的请求4要素
1、请求地址:
https://open.jackyun.com/open-platform/developer/intercept/testtool/buildparamandrequest
2、请求方法:post
3、请求头
-
Host: open.jackyun.com
-
Connection: keep-alive
-
Content-Length: 6677
-
sec-ch-ua: ";Not A Brand";v="99", "Chromium";v="94"
-
Accept: */*
-
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
-
X-Requested-With: XMLHttpRequest
-
sec-ch-ua-mobile: ?0
-
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Core/1.94.200.400 QQBrowser/11.8.5310.400
-
sec-ch-ua-platform: "Windows"
-
Origin: https://open.jackyun.com
-
Sec-Fetch-Site: same-origin
-
Sec-Fetch-Mode: cors
-
Sec-Fetch-Dest: empty
-
Referer: https://open.jackyun.com/developer/console/page/testtool.html?apiname=erp.goods.skuimportbatch&from=jackyunweb
-
Accept-Encoding: gzip, deflate, br
-
Accept-Language: zh-CN,zh;q=0.9
-
Cookie: 53revisit=1680485326445; _ati=688404030667; Hm_lvt_4293e6f16d3e0252d48cf7a1252f995f=1687759229; Qs_lvt_352880=1680485326%2C1683769042%2C1687759230; Qs_pv_352880=902333099737909600%2C3189451156430100000%2C3125342331411176400%2C2032507965245106700%2C3752838942850185700; jkusername=88888; yhusername=visitor; SESSION=0891f98a-1f45-4a2e-95c9-fbf046636678; openplatfrom=jackyunweb
4、请求体
bizcontent=[{"skuImageUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","goodsNameEn":"","isPeriodManage":0,"rightGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","isDoorService":0,"isProxySale":0,"skuHeight":"","shelfLiftUnit":"年","goodsName":"山梅花蜜桃晶采亮肤面膜","goodsField8":"货品属性B","goodsField9":"货品属性B","goodsField10":"货品属性B","goodsField4":" 货品属性B","goodsField11":"货品属性B","goodsField5":"货品属性B","goodsField12":"货品属性B","goodsField6":"货品属性B","goodsField13":"货品属性B","goodsField7":"货品属性B","goodsField14":"货品属性B","goodsField15":"货品属性B","mainGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","goodsField16":"货品属性B","goodsField17":"货品属性B","goodsField18":"货品属性B","goodsField19":"货品属性B","cateCode":"0101","moduleContent":[{"type":1,"showOder":"1","title":"标题","content":"这是描述"}],"skuNo":"HP001","goodsField1":"货品属性B","goodsField2":"货品属性B","goodsField3":"货品属性B","descript":"<p>这是很好的书!</p> <p><img src=\"http://jkyun.oss-cn-hangzhou.aliyuncs.com/longterm/45/system/erp/445554288029867136/1204140161368877696.jpg?Expires=4780344693&OSSAccessKeyId=LTAIh08vjrfC7HV0&Signature=Rb2zTo8%2BRXnWUx8uoBmMMJ3pgfs%3D#O1CN01vPRtFX1CP18G9GBqN-101450072.jpg\" alt=\"\" /></p> <p> </p>","belowGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","ownerCode":"34343","isCustomizProduction":0,"isSyncToItem":"0","goodsAlias":"","shelfLife":3,"platCateId":"110201","goodsAttr":1,"isSerialManagement":0,"skuBarcode":"123fee","materialImgUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","sellInfo":"商品卖点","topGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","skuField29":"A","skuField9":"A","skuField8":"A","skuField25":"A","skuField7":"A","skuField26":"A","skuField6":"A","skuField27":"A","skuField5":"A","skuField28":"A","skuField4":"A","skuField3":"A","skuField2":"A","skuField1":"A","cateName":"笔记本","outSkuCode":"12232","skuField30":"A","skuField18":"A","skuField19":"A","brandName":"","unitName":"件","skuField14":"A","skuField15":"A","skuField16":"A","skuField17":"A","isPickupCard":0,"goodsMemo":"","skuWidth":"","volume":0,"skuField21":"A","leftGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","skuField22":"A","isProsaleProduct":0,"goodsVideoUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","skuField23":"A","isProductionMaterials":0,"skuField24":"A","fixPrice":1.20,"skuWeight":"","skuField20":"A","goodsField20":"货品属性B","isBatchManagement":0,"goodsField21":"货品属性B","goodsField22":"货品属性B","goodsField23":"货品属性B","goodsField24":"货品属性B","goodsField25":"货品属性B","costValuationMethod":0,"goodsField26":"货品属性B","goodsField27":"货品属性B","goodsField28":"货品属性B","goodsField29":"货品属性B","warehouseCode":"C0001","skuName":"规格1","skuField10":"A","skuField11":"A","mainBarcode":"CODE0001","skuField12":"A","abcCate":"A类","skuField13":"A","goodsNo":"1196","goodsField30":"货品属性B","skuLength":"","isPaidService":0}]&method=erp.goods.skuimportbatch&appkey=28773818&version=v1.0&contenttype=json
-
JMeter填写请求4要素
1、http取样器填写内容。
2、请求头分别填写在:http信息头管理器和http cookie管理器。
新增接口脚本优化
接口脚本需要参数化的内容包括如下:
1、公共信息的参数化:前缀
2、请求参数的参数化:前缀+当前时间+随机数
3、断言:前缀+当前时间
-
公共信息参数化
前缀信息进行参数化:
-
获取当前时间的函数介绍
获取当前时间的函数:${__time(YMdHm,)}
-
随机函数的介绍
生成的随机函数:${__Random(1,100,)}
-
请求参数的参数化
将上面1-3中参数进行拼接,如下:${prename}${__time(YMdHm,)}${__Random(1,100,)}
将拼接后的参数代替请求参数中的4个必填字段的固定值,脚本如下:
{"skuImageUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","goodsNameEn":"","isPeriodManage":0,"rightGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","isDoorService":0,"isProxySale":0,"skuHeight":"","shelfLiftUnit":"年","goodsName":"山梅花蜜桃晶采亮肤面膜","goodsField8":"货品属性B","goodsField9":"货品属性B","goodsField10":"货品属性B","goodsField4":" 货品属性B","goodsField11":"货品属性B","goodsField5":"货品属性B","goodsField12":"货品属性B","goodsField6":"货品属性B","goodsField13":"货品属性B","goodsField7":"货品属性B","goodsField14":"货品属性B","goodsField15":"货品属性B","mainGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","goodsField16":"货品属性B","goodsField17":"货品属性B","goodsField18":"货品属性B","goodsField19":"货品属性B","cateCode":"0101","moduleContent":[{"type":1,"showOder":"1","title":"标题","content":"这是描述"}],"skuNo":"${prename}${__time(YMdHm,)}${__Random(1,100,)}","goodsField1":"货品属性B","goodsField2":"货品属性B","goodsField3":"货品属性B","descript":"<p>这是很好的书!</p> <p><img src=\"http://jkyun.oss-cn-hangzhou.aliyuncs.com/longterm/45/system/erp/445554288029867136/1204140161368877696.jpg?Expires=4780344693&OSSAccessKeyId=LTAIh08vjrfC7HV0&Signature=Rb2zTo8%2BRXnWUx8uoBmMMJ3pgfs%3D#O1CN01vPRtFX1CP18G9GBqN-101450072.jpg\" alt=\"\" /></p> <p> </p>","belowGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","ownerCode":"34343","isCustomizProduction":0,"isSyncToItem":"0","goodsAlias":"","shelfLife":3,"platCateId":"110201","goodsAttr":1,"isSerialManagement":0,"skuBarcode":"${prename}${__time(YMdHm,)}${__Random(1,100,)}","materialImgUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","sellInfo":"商品卖点","topGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","skuField29":"A","skuField9":"A","skuField8":"A","skuField25":"A","skuField7":"A","skuField26":"A","skuField6":"A","skuField27":"A","skuField5":"A","skuField28":"A","skuField4":"A","skuField3":"A","skuField2":"A","skuField1":"A","cateName":"笔记本","outSkuCode":"${prename}${__time(YMdHm,)}${__Random(1,100,)}","skuField30":"A","skuField18":"A","skuField19":"A","brandName":"","unitName":"件","skuField14":"A","skuField15":"A","skuField16":"A","skuField17":"A","isPickupCard":0,"goodsMemo":"","skuWidth":"","volume":0,"skuField21":"A","leftGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","skuField22":"A","isProsaleProduct":0,"goodsVideoUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","skuField23":"A","isProductionMaterials":0,"skuField24":"A","fixPrice":1.2,"skuWeight":"","skuField20":"A","goodsField20":"货品属性B","isBatchManagement":0,"goodsField21":"货品属性B","goodsField22":"货品属性B","goodsField23":"货品属性B","goodsField24":"货品属性B","goodsField25":"货品属性B","costValuationMethod":0,"goodsField26":"货品属性B","goodsField27":"货品属性B","goodsField28":"货品属性B","goodsField29":"货品属性B","warehouseCode":"C0001","skuName":"规格1","skuField10":"A","skuField11":"A","mainBarcode":"CODE0001","skuField12":"A","abcCate":"A类","skuField13":"A","goodsNo":"${prename}${__time(YMdHm,)}${__Random(1,100,)}","goodsField30":"货品属性B","skuLength":"","isPaidService":0}
-
断言
查询接口脚本
查询接口请求4要素:
1、请求地址:https://open.jackyun.com/open-platform/developer/intercept/testtool/buildparamandrequest
2、请求方法:post
3、请求头:
-
Host: open.jackyun.com
-
Connection: keep-alive
-
Content-Length: 893
-
sec-ch-ua: ";Not A Brand";v="99", "Chromium";v="94"
-
Accept: */*
-
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
-
X-Requested-With: XMLHttpRequest
-
sec-ch-ua-mobile: ?0
-
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Core/1.94.200.400 QQBrowser/11.8.5310.400
-
sec-ch-ua-platform: "Windows"
-
Origin: https://open.jackyun.com
-
Sec-Fetch-Site: same-origin
-
Sec-Fetch-Mode: cors
-
Sec-Fetch-Dest: empty
-
Referer: https://open.jackyun.com/developer/console/page/testtool.html?apiname=erp.storage.goodslist&from=jackyunweb
-
Accept-Encoding: gzip, deflate, br
-
Accept-Language: zh-CN,zh;q=0.9
-
Cookie: 53revisit=1680485326445; _ati=688404030667; Hm_lvt_4293e6f16d3e0252d48cf7a1252f995f=1687759229; Qs_lvt_352880=1680485326%2C1683769042%2C1687759230; Qs_pv_352880=902333099737909600%2C3189451156430100000%2C3125342331411176400%2C2032507965245106700%2C3752838942850185700; jkusername=88888; yhusername=visitor; SESSION=0891f98a-1f45-4a2e-95c9-fbf046636678; acw_tc=276aede816895769228234156e315d1dddf88a5616cf1761833897fff3e36a; openplatfrom=jackyunweb
4、请求体
appkey=28773818&method=erp.storage.goodslist&contenttype=JSON&version=v1.0&pageIndex=0&pageSize=1&startDate=&skuName=&isBlockup=&startDateModifiedGoods=&goodsNo=test20230717&endDateModifiedSku=&endDate=&cateName=&abcCate=&isPackageGood=&skuIsBlockup=&skuBarcode=&goodsName=&assistBarcode=&endDateModifiedGoods=&startDateModifiedSku=&bizcontent={"pageIndex":"0","pageSize":"1","startDate":"","skuName":"","isBlockup":"","startDateModifiedGoods":"","goodsNo":"${skuno}","endDateModifiedSku":"","endDate":"","cateName":"","abcCate":"","isPackageGood":"","skuIsBlockup":"","skuBarcode":"","goodsName":"","assistBarcode":"","endDateModifiedGoods":"","startDateModifiedSku":""}
查询货品接口断言:
上下游接口传值
1、上游接口使用边界提取器提取值,截图如下:
2、下游接口引用参数:${skuno}
JMeter实现接口的性能测试
性能测试分析
-
实际使用场景
系统上线之前的货品准备工作、双十一大促之前的货品准备工作,多名订单操作人员或者仓管员同时导入货品,存在导入货品功能的并发,且每个操作人员导入的货品编号不同(该系统不允许重复导入货品编号相同的货品)。
-
JMeter模拟思路
使用JMeter的“if控制器”控制模拟不同的操作人员,且不同的操作员导入货品编号的随机数范围不同,多名操作人员使用csv文件存储;比如,操作员A导入货品编号为:1-100;操作员导入货品编号为:101-200,以此类推。
比如随机数:101-200的新增货品接口请求参数:
{"skuImageUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","goodsNameEn":"","isPeriodManage":0,"rightGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","isDoorService":0,"isProxySale":0,"skuHeight":"","shelfLiftUnit":"年","goodsName":"山梅花蜜桃晶采亮肤面膜","goodsField8":"货品属性B","goodsField9":"货品属性B","goodsField10":"货品属性B","goodsField4":" 货品属性B","goodsField11":"货品属性B","goodsField5":"货品属性B","goodsField12":"货品属性B","goodsField6":"货品属性B","goodsField13":"货品属性B","goodsField7":"货品属性B","goodsField14":"货品属性B","goodsField15":"货品属性B","mainGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","goodsField16":"货品属性B","goodsField17":"货品属性B","goodsField18":"货品属性B","goodsField19":"货品属性B","cateCode":"0101","moduleContent":[{"type":1,"showOder":"1","title":"标题","content":"这是描述"}],"skuNo":"${prename}${__time(YMdHm,)}${__Random(101,200,)}","goodsField1":"货品属性B","goodsField2":"货品属性B","goodsField3":"货品属性B","descript":"<p>这是很好的书!</p> <p><img src=\"http://jkyun.oss-cn-hangzhou.aliyuncs.com/longterm/45/system/erp/445554288029867136/1204140161368877696.jpg?Expires=4780344693&OSSAccessKeyId=LTAIh08vjrfC7HV0&Signature=Rb2zTo8%2BRXnWUx8uoBmMMJ3pgfs%3D#O1CN01vPRtFX1CP18G9GBqN-101450072.jpg\" alt=\"\" /></p> <p> </p>","belowGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","ownerCode":"34343","isCustomizProduction":0,"isSyncToItem":"0","goodsAlias":"","shelfLife":3,"platCateId":"110201","goodsAttr":1,"isSerialManagement":0,"skuBarcode":"${prename}${__time(YMdHm,)}${__Random(101,200,)}","materialImgUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","sellInfo":"商品卖点","topGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","skuField29":"A","skuField9":"A","skuField8":"A","skuField25":"A","skuField7":"A","skuField26":"A","skuField6":"A","skuField27":"A","skuField5":"A","skuField28":"A","skuField4":"A","skuField3":"A","skuField2":"A","skuField1":"A","cateName":"笔记本","outSkuCode":"${prename}${__time(YMdHm,)}${__Random(101,200,)}","skuField30":"A","skuField18":"A","skuField19":"A","brandName":"","unitName":"件","skuField14":"A","skuField15":"A","skuField16":"A","skuField17":"A","isPickupCard":0,"goodsMemo":"","skuWidth":"","volume":0,"skuField21":"A","leftGoodsUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","skuField22":"A","isProsaleProduct":0,"goodsVideoUrl":"http://wdgjtest.oss-cn-hangzhou.aliyuncs.com/45/341960689798062080.jpg?Expires=4677564907&OSSAccessKeyId=LTAI2P5paDiiYDCJ&Signature=7gKXbqG2QWeG7sUByBk8J9ummno%3D","skuField23":"A","isProductionMaterials":0,"skuField24":"A","fixPrice":1.2,"skuWeight":"","skuField20":"A","goodsField20":"货品属性B","isBatchManagement":0,"goodsField21":"货品属性B","goodsField22":"货品属性B","goodsField23":"货品属性B","goodsField24":"货品属性B","goodsField25":"货品属性B","costValuationMethod":0,"goodsField26":"货品属性B","goodsField27":"货品属性B","goodsField28":"货品属性B","goodsField29":"货品属性B","warehouseCode":"C0001","skuName":"规格1","skuField10":"A","skuField11":"A","mainBarcode":"CODE0001","skuField12":"A","abcCate":"A类","skuField13":"A","goodsNo":"${prename}${__time(YMdHm,)}${__Random(101,200,)}","goodsField30":"货品属性B","skuLength":"","isPaidService":0}
性能测试脚本设计
csv数据文件设置:
性能脚本优化
csv文件参数引用,如下:
添加“if控制器”和事务控制器,如下:
注意:if控制器这个勾去掉。
线程组设置:
启动性能测试脚本生成聚合报告:
备注:本次只实现一个货品一个sku的场景。
注意:本文档借用吉客云OPEN API文档,电商erp系统为吉客云电商erp系统。
总结:
感谢每一个认真阅读我文章的人!!!
作为一位过来人也是希望大家少走一些弯路,如果你不想再体验一次学习时找不到资料,没人解答问题,坚持几天便放弃的感受的话,在这里我给大家分享一些自动化测试的学习资源,希望能给你前进的路上带来帮助。
软件测试面试文档
我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。
视频文档获取方式:
这份文档和视频资料,对于想从事【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!以上均可以分享,点下方小卡片即可自行领取。