一、moco jar包下载及运行
1、访问https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/1.1.0/,下载moco-runner-1.1.0-standalone.jar,将下载下来的jar包拷贝至指定路径
2、在jar所在的路径下,新建json文件,输入以下代码,进行保存
[
{
"description" : "Mock技术模拟",
"request" :{
"uri" : "/mock_demo"
},
"response" : {
"text" : "<p>Mock Technology</p>"
}
}
]
3、在jar包所在目录,打开cmd,运行以下命令
java -jar moco-runner-1.1.0-standalone.jar http -p 9999 -c test.json
"""
http 指接口使用http协议
-p 9999 指使用8899端口
-c test.json 指需要运行的json文件
"""
二、配置不同的请求
2.1 构建get请求参数
{
"description": "构建get请求参数",
"request" : {
"method" : "GET",
"uri" : "/api/query/recharge",
"queries": {
"mobile": "18026985748",
"amount": "100"
}
},
"response" : {
"status" : 200,
"json" : {
"retcode": 0,"msg" : "话费充值成功!!!"}
}
}
2.2 构建post请求form表单数据
{
"description": "构建post请求表单数据",
"request" : {
"method" : "POST",
"uri" : "/api/forms/login",
"forms"