Jmeter是一款优秀的开源测试工具, 是每个资深测试工程师,必须掌握的测试工具,熟练使用Jmeter能大大提高工作效率。
本文将通过一个实际的测试例子, 来讲解Jmeter的基本用法。
Jmeter 是一款使用Java开发的,开源免费的,测试工具, 主要用来做功能测试和性能测试(压力测试/负载测试).
而且用Jmeter 来测试 Restful API, 非常好用。
如果你用Jmeter去对Web进行功能测试,或者性能测试。 你必须熟练HTTP协议,才能学好Jmeter。 否则你很难理解Jmeter中得概念。
官方网站:http://jmeter.apache.org/
解压后, 运行 “bin/jmeter.bat”
Jmeter 是支持中文的, 启动Jmeter 后, 点击 Options -> Choose Language 来选择语言
目标: 获取JEECG BOOT 在线开发模块的表单字段元数据
第一步: 发送request 获取字段元数据
http://127.0.0.1:8080/jeecg-boot/online/cgform/api/getColumns/22d36f6b7c08457e9659c54fcfa8eec5
从这个请求的response 中获取到表单字段信息. 比如:
{"success":true,"message":"操作成功!","code":0,"result":{"code":"22d36f6b7c08457e9659c54fcfa8eec5","formTemplate":"1","description":"kkkk","currentTableName":"kkkk","tableType":1,"paginationFlag":"Y","checkboxFlag":"Y","scrollFlag":1,"columns":[{"title":"用户名","dataIndex":"name","align":"center","customRender":null,"scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"年龄","dataIndex":"age","align":"center","customRender":null,"scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"金额","dataIndex":"money","align":"center","customRender":null,"scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"个税","dataIndex":"geshui","align":"center","customRender":null,"scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"日期","dataIndex":"dates","align":"center","customRender":null,"scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"cc","dataIndex":"ccc2","align":"center","customRender":null,"scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"aaa","dataIndex":"aaa","align":"center","customRender":null,"scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"dd","dataIndex":"dddd","align":"center","customRender":null,"scopedSlots":{"customRender":"dateSlot"},"hrefSlotName":null,"sorter":false},{"title":"iii","dataIndex":"iii","align":"center","customRender":null,"scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"do","dataIndex":"do","align":"center","customRender":null,"scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"tttt","dataIndex":"ttttt","align":"center","customRender":null,"scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"开关","dataIndex":"swtich","align":"center","customRender":"swtich","scopedSlots":null,"hrefSlotName":null,"sorter":false},{"title":"dddd","dataIndex":"dddd22","align":"center","customRender":"dddd22","scopedSlots":null,"hrefSlotName":null,"sorter":false}],"hideColumns":[],"dictOptions":{"dddd22":[{"value":"Y","text":"是","title":"是"},{"value":"N","text":"否","title":"否"}],"swtich":[{"value":"Y","text":"是","title":"是"},{"value":"N","text":"否","title":"否"}]},"cgButtonList":[],"fieldHrefSlots":[],"enhanceJs":null,"foreignKeys":[],"pidField":null,"hasChildrenField":null,"textField":null},"timestamp":1591150936483}
第二步: 发送request 需要设置head参数 X-Access-Token
必须新建一个Thread Group, jmeter的所有任务都必须由线程处理,所有任务都必须在线程组下面创建。
比如我要发送一个Get 方法的http 请求:http://127.0.0.1:8080/jeecg-boot/online/cgform/api/getColumns/22d36f6b7c08457e9659c54fcfa8eec5
可以按照下图这么填
选中上一步新建的HTTP request. 右键,新建一个Http Header manager. 添加一个header
View Results Tree 是用来看运行的结果的
到这里。 我们已经成功运行起来了。
线程数改成500左右
压测一般都先测单服务,单服务通过后测集群
单机吞吐量至少2000/sec