1:Mock简介
1.1:Mock可以做什么
Mock可以模拟一个http接口的后台响应,就这么简单,可以模拟request、response
1.2:如何获取Mock
下载Moco Runner standlone:Standalone Moco Runner
2:Mock模拟一个Get请求
2.1:Mock模拟一个不带参数的Get请求
2.1.1:创建json文件 Test.json
[
{
"description":"这是Mock接口的Demo",
"request":{
"uri":"/GetDemo",
"method":"get"
},
"response":{
"text":"This is Get request"
}
}
]
2.1.2:运行moco-runner-0.11.0-standalone
cmd中运行:java -jar ./moco-runner-0.11.0-standalone.jar http -p 8888 -c Test.json
2.1.3:浏览器访问这个地址
2.2:Mock模拟一个带参数的Get请求
1:Test.json
[
{
"description":"这是Mock接口的Demo",
"request":{
"uri":"/GetDemo",
"method":"get",
"queries":{
"name":"Anndy",
"age":"18"
}
},
"response":{
"text":"This is Get request name=Anndy"
}
}
]
2:启动 java -jar ./moco-runner-0.11.0-standalone.jar http -p 8888 -c Test.json
3:浏览器访问:http://localhost:8888/GetDemo?name=Anndy&age=18
3:Mock模拟POST请求
3.1:模拟不带参数的POST请求
1:Test.json
[
{
"description":"这是Mock接口的Demo",
"request":{
"uri":"/PostDemo",
"method":"Post"
},
"response":{
"text":"This is Post request"
}
}
]
2:启动 java -jar ./moco-runner-0.11.0-standalone.jar http -p 8888 -c Test.json
3:Jmeter访问
Post类型接口没办法直接用浏览器访问所以用jmeter
3.2:带参数的POST请求
1:Test.json
注意:这里的参数需要些forms而不是queries
[
{
"description":"这是Mock接口的Demo",
"request":{
"uri":"/PostDemo",
"method":"Post",
"forms":{
"name":"Anndy",
"age":"18"
}
},
"response":{
"text":"This is Post request"
}
}
]
2:Jmeter访问
来源:CSDN
作者:AnndyTuo
链接:https://blog.csdn.net/hujyhfwfh2/article/details/86376404