一、环境安装
见:moco环境安装
这里安装的目前最新:moco-runner-1.3.0-standalone.jar,jdk-19_windows-x64_bin.exe,jdk环境变量配置好
moco地址:https://github.com/dreamhead/moco
api文档地址: https://github.com/dreamhead/moco/blob/master/moco-doc/apis.md
在moco安装历经下,cmd窗口,启动命令:java -jar moco-runner-1.3.0-standalone.jar http -p 8888 -c test01.json
moco只关注服务器的配置,也就是客户端与服务端,或者更加具体的说就是请求和响应。
二、下面模拟使用Postmen请求
新建一个one_response.json文件:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
启动moco服务:java -jar moco-runner-1.3.0-standalone.jar http -p 8888 -c one_response.json
使用Postmen去访问:http://localhost:8888/onelogin
cmd窗口moco服务:
三、moco模拟多个接口案例
创建hotel.json文件,里面有登录和系统两个接口请求
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 [ 2 { 3 "request": 4 { 5 "method":"post", 6 "uri":"/system", 7 "json": 8 { 9 "ph":"88888888", 10 "name":"admin", 11 "code":"8888888888888888888888" 12 } 13 }, 14 "response": 15 { 16 "file":"system_response.json" 17 } 18 }, 19 20 { 21 "request": 22 { 23 "method":"post", 24 "uri":"/login", 25 "json": 26 { 27 "username":"login_admin", 28 "password":"admin" 29 } 30 }, 31 "response": 32 { 33 "file":"login_response.json" 34 } 35 } 36 ]
在同一级文件夹下,通过login_response.json、system_response.json将请求数据分离出来
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 { 2 "status":0, 3 "msg":"ok", 4 "data": 5 { 6 "username":"login_admin", 7 "userID":18, 8 "token":"as342sdsdsdsddddt" 9 } 10 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 { 2 "status":0, 3 "msg":"ok", 4 "data": 5 { 6 "room":"201" 7 "startTime":"2022-11-10", 8 "endTime":"2022-11-11", 9 "vpr":"88888888" 10 } 11 }
启动moco服务:java -jar moco-runner-1.3.0-standalone.jar http -p 8888 -c hotel.json
就可以使用Postmen通过http://localhost:8888/login、http://localhost:8888//system请求到数据了
2022-11-5笔记