開發過程當中須要依賴一些接口,這些接口要麼是搭建環境困難,要麼是尚未實現,要麼是交互比較複雜。這種狀況下,使用mock server來mock這些接口,以便開發和測試可以正常進行。html
mocojava
Moco is an easy setup stub framework.python
首先請安裝jdkgit
Standalone Moco Runnergithub
視頻壓縮包裏也有當前最新版本:D:\APK\Genymotion\03 python接口自動化測試全\11_start_mock_serverweb
如內容以下:json
[
{
"request" :
{
"uri" : "/"
},
"response" :
{
"text" : "mock server started"
}
},
{
"request" :
{
"uri" : "/hello"
},
"response" :
{
"text" : "kitty"
}
},
{
"request" :
{
"uri" : "/itest"
},
"response" :
{
"text" : "www.itest.info"
}
}
]app
在cmd下運行:注意jar文件要與json文件在同一個目錄 下maven
D:\APK\Genymotion\03 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