MOCK SERVER 接口模拟

开发过程中需要依赖一些接口,这些接口要么是搭建环境困难,要么是还没有实现,要么是交互比较复杂。这种情况下,使用mock server来mock这些接口,以便开发和测试能够正常进行。

工具选型

moco

Moco is an easy setup stub framework.

安装

需要moco jar包的,也可留言索取。

如内容如下:

[
{
"request" :
{
"uri" : "/"
},
"response" :
{
"text" : "mock server started"
}
},
{
"request" :
{
"uri" : "/hello"
},
"response" :
{
"text" : "kitty"
}
},
{
"request" :
{
"uri" : "/itest"
},
"response" :
{
"text" : "www.itest.info"
}
}
]

在cmd下运行:注意jar文件要与json文件在同一个目录 下

D:APKGenymotion3 python接口自动化测试全11_start_mock_server>java -jar moco-runner-0.10.0-standalone.jar http -p 12306 -c 11_config.json
28 三月 2019 11:03:28 [main] INFO Server is started at 12306
28 三月 2019 11:03:28 [main] INFO Shutdown port is 51180
28 三月 2019 11:03:47 [nioEventLoopGroup-3-2] INFO Request received:

GET / HTTP/1.1
Host: localhost:12306
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Content-Length: 0

在页面上访问http://localhost:12306/hello

则页面上显示“

kitty


原文地址:https://www.cnblogs.com/bzdmz/p/10613643.html