mock测试:JMeter工具
接上文《mock框架与测试一》
本文将简单介绍mock框架搭建完成后,使用JMeter执行接口验证测试的方法:
JMeter下载:
官网:https://jmeter.apache.org/
JMeter打开:
了解下jmeter打开方式:
1、JMeter解压路径bin文件夹下打开jmeter.bat,命令行窗口无需关闭。
2、通过ApacheJMeter.jar鼠标右键打开java程序
3、通过java指令,在当前目录打开命令行窗口,输入java -jar ApacheJMeter.jar
切入正题:使用jmeter执行接口测试
先启动moco服务:运行java -jar moco.jar包 协议 -p端口 -c json文件
1、 Moco框架的http协议get方法的Mock实现
- 不带参数的get实现
[
{
"description":"This is Get request without paramter",
"request":{
"uri":"/getdemo",
"method":"get"
},
"response":{
"text":"This is response for Get request without paramter "
}
}
]
配置jmeter:
1、新建线程组——》新建http请求——》新增查看结果树
2、编辑请求
3、启动请求,查看响应返回数据
- 带参数的get实现:
线程组——》新建http请求——》添加结果树
添加参数:
启动请求查看结果:
2、 Moco框架的http协议Post方法的Mock实现 - 不带参数的post请求
[
{
"description":"This is Post request",
"request":{
"uri":"/postdemo",
"method":"post"
},
"response":{
"text":"This is Post response"
}
}
]
1、配置post请求
2、查看响应结果:
- 带参数的post请求
[
{
"description":"This is Post request with paramter",
"request":{
"uri":"/postwithparam",
"method":"post",
"forms":{
"name":"zhangsan",
"age":"18"
}
},
"response":{
"text":"This is Post response with paramter"
}
}
]
1、配置参数
2、查看响应结果:
3、 Moco框架如何加入Cookies
- 带cookies信息的get请求
[
{
"description":"This is Get request with cookies",
"request":{
"uri":"/get/with/cookies",
"method":"get",
"cookies":{
"login":"true"
}
},
"response":{
"text":"This is get response with cookies"
}
}
]
1、配置cookie参数,新建该请求的cookie管理器-》配置cookie参数
2、查看响应结果:
- 带cookies信息的post请求
[
{
"description":"This is Post request with cookies",
"request":{
"uri":"/post/with/cookies",
"method":"post",
"cookies":{
"login":"true"
},
"json":{
"name":"zhangsan",
"age":"18"
}
},
"response":{
"status":200,
"json":{
"zhangsan":"success",
"status":"1"
}
}
}
]
1、配置参数
2、查看响应结果
3、 Moco框架如何加入Header
- Header请求头信息的格式在get和post请求中是一致的。
{
"description":"This is Post request with header",
"request":{
"uri":"/postwithheader",
"method":"post",
"headers":{
"content-type":"application/json"
},
"json":{
"name":"zhangsan",
"age":"18"
}
},
"response":{
"text":"This is Post response with paramter"
}
}
1、配置头参数
2、查看响应数据
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhiajaif
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
微信运动停用后别人还能看到步数吗
PHP中文网 07-22