mock
一、mockServer
1.1、什么是mock
Mock---》替身 server--〉服务 测试替身的服务
mockserever的作用:
现今的业务系统很少有孤立存在的,它们或多或少需要使用兄弟团队或是其他公司提供的服务,这给我们的联调和测试造成了麻烦。对于这种情况,我们常见的解决方案是搭建一个临时的server,模拟那些服务,提供数据进行联调和测试。这就是 mock server 出现原因
1.2、不同角色对mock的使用场景
1.2.1、前端
前端已写好⻚⾯,但是后端的接⼝没写好,那么前端程序员正确的姿势是什么?正确的姿势就是模拟后端。 现在前端程序员来模拟后端返回的产品列表的数据:
[
{
"request":
{
"method": "get",
"uri": "/products"
},
"response":
{
"json":{
"name": "asdfghjkl",
"type": "WEB",
"version": "V1.0.0",
"master": "chenli",
"description": "this is a test api"
}
}
}
]
启动命令:java -jar moco-runner-1.3.0-standalone.jar http -p 12306 -c product.json
1.2.2、后端
A给B服务⼀个⻋牌号,那么B返回⻋辆的其他信息
[ { "request": { "method": "post", "uri": "/parking", "json": { "park": "A888888" } }, "response": { "json": { "park": "A888888", "in": "2022-01-14 00:00:00", "out": "2022-01-14 08:00:00", "money": "$5", "master": "chenli" } } } ]
1.2.3、测试
在测试过程中没有数据那么
1、自己造数据
2、自己moco数据
[ { "request": { "method": "get", "uri": "/products" }, "response": { "json": [ { "name": "asdfghjkl", "type": "WEB", "version": "V1.0.0", "master": "chenli", "description": "this is a test api" }, { "name": "asdfghjkl", "type": "WEB", "version": "V1.0.0", "master": "chenli", "description": "this is a test api" } ] } } ]
什么是moco
下载地址;https://github.com/dreamhead/moco
链接:https://pan.baidu.com/s/11D59EN95SHFqgNyfkSHYjA
提取码:26bh
下载成功后的jar包放在跟json数据同级目录下。