一、搭建mock server
mock工具很多,这里我们选择用简单易操作的moco服务器
二、使用mock server
从最简单的hello world开始,使用json做为交互数据使用,编辑config.json为如下文件:
[
{
"request" :
{
"uri" : "/hello"
},
"response" :
{
"text" : "World!"
}
}
]
启动mock server
java -jar moco-runner-0.10.0-standalone.jar http -p 12888 -c config.json
三:验证
使用httpRequest相关发送get /hello,就会返回world
四:丰富接口后使用unittest、requests写的接口用例如下,包括了get、post、put和deletet接口,代码如下,有需要的可以参考:
importunittest
importrequests
importjson
classTestInterFace(unittest.TestCase):
defsetUp(self):
#print "xxxx"
self.domain='http://localhost:12888'self.jso