怎么进行mock接口测试


1.找到一台linux机器或者本地执行也行,解压压缩包,然后再lib下执行 nohup java -jar mock-engine-1.0-SNAPSHOT.jar &   

2.服务启动之后,进行建立mock链接。请求地址是服务器ip+38802/mock/execute/script

3.设置匹配规则 matchRule (matchPath为mock后的url)也可以自定义进行添加headers和返回值

4.responses  进行添加返回值(需要进行转义)

5.设置链接id 唯一不能重复

6.发起请求,就可以在这个mock服务上创建一个链接

7.请求mock接口,url为服务部署的IP+29998+mock的url

import requests


def mock_test():
"""

:return:
"""
url = 'http://10.111.228.571:38802/mock/execute/script'
body = {
"comment": "",
"name": "test",
"request": {
"bodyType": "JSON",
"type": "",
"matchRule": {
"matchMethod": "POST",
"matchBodyList": [],
"matchQuerys": {},
"matchHeaders": {},
"matchPath": "/api/app_mix/first" #mock的url
},
"reqRecordNum": 1,
"extraParams": {}
},
"lastmodifyTime": 1570862760,
"type": "http",
"id": 1011, #链接id 唯一不能重复
"responses": [{
"isEnable": 'true',
"callBackList": [],
"response": {
'body': """""", # 返回值参数,需要进行转义
"pbConfig": {},
"httpStatus": 200,
"headers": {"Content-Type": "application/json"},
"bodyType": "JSON"
},
"config": {
"delay": "0",
"name": "q",
"weight": 1,
"delays": "",
"delaysWeight": "",
"rate": "",
"id": 1011
},
"id": 1011,
"isProxy": 'false'
}]
}
result = requests.post(url, json=body)
print result





2.十一:

(1) 让返回值返回时间搓:${__time(1,)}


(2){"key":"QuoteId","rule":"$.QuoteId","value":""}++++++=${QuoteId} 根据传参数来返回相同的值


(3)随机数: LAI-${__Random(110040000,110099999)}


(4)让请求链接可以随便加get参数 /test/*

(5)服务断掉 重启链接: 服务器IP+:38802/mock/reload

相关