mock测试:使用moco-runner模拟多个接口
利用json文件模拟接口请求
demo.json内容如下:
[ { "description":"mock接口demo", "request":{ "uri":"/demo" }, "response":{ "text":"第一个mock接口demo" } } ]
demo_get.json内容如下:
[ { "description":"mock接口demo:带参数的get请求", "request":{ "uri":"/demo_get", "method":"get", "queries":{ "param1":"1" } }, "response":{ "text":"mock接口demo返回:带参数的get请求", "headers":{ "Content-Type":"text/html;charset=utf-8" } } } ]
demo_post.json内容如下:
[ { "description":"mock接口demo:带参数的post请求", "request":{ "uri":"/demo_post", "method":"post", "forms":{ "param1":"1", "param2":"2" } }, "response":{ "status":200, "text":"mock接口demo返回:带参数的post请求", "headers":{ "Content-Type":"text/html;charset=utf-8" }, "json":{ "code":0, "msg":"成功", "data":"真的不错" } } } ]
使用moco-runner模拟多个接口
一、新建global.json文件,并将"demo.json"等多个接口描述文件放到mocorunner文件夹下
global.json内容如下:
[ { "include":"demo.json" }, { "include":"demo_get.json" }, { "include":"demo_post.json" } ]
二、执行
java -jar ./moco-runner-1.3.0-standalone.jar http -p 8888 -g global.json