接口自动化测试-Mock Get和Post请求

Mock可以模拟一个http接口的后台响应,可以模拟request,response 

下载 moco-runner-0.11.0-standalone.jar

下载链接: https://pan.baidu.com/s/1bmFzvJPRnDlQ-cmuJ_3iRg 提取码: kpjv

确保安装了jdk,cmd下可以运行java -version

一、模拟不带参的get请求

#代码中的description行可以不写;一般结构为description,request,response,除description外,其它值均为键值对形式;request定义uri(接口地址),method(请求方式),queries 或 forms;

参考代码: 

[
{
"description":"this is a no param get",
"request":{
"uri":"/get",
"method":"Get"
},
"response":{
"text":"Yeah,you sucess"
}

}
]

 二、模拟带参数的get请求;

参数使用"queries"

 三、发送不带参数Post;

post请求不能使用浏览器访问,可以使用Postman或Jmeter工具;

 浏览器访问结果如下:

 Postman设置及结果如下:

Jmeter设置及结果如下:

 四、发送带参数的Post请求;参数使用"forms"

 Postman设置及结果如下图;键值(key,value)都传对了,status才显示200,否则显示400;

 jmeter设置及结果如下图;

猜你喜欢

转载自www.cnblogs.com/canglongdao/p/12174046.html