接口测试-mock测试:实例

拟墨画扇 提交于 2019-12-06 12:15:14

实际事例

1.get接口实例

一段json数据,json的格式

[{
        "key1": "values",
        "key2": "values"
    },
    {
        "key1": "values",
        "key2": "values"
    }
]

代码实例

{
    "description": "模拟获取某个功能的具体信息接口,get请求和响应,返回json格式数据",
    "request": {
        "method": "get",
        "url": "/book_info",
        "queries": {
            "bookname": "软件测试",
            "checkstatus": "on"
        }
    },
    "response": {
        "json": {
            "error_code": 0,
            "reason": "successed",
            "name": "软件测试",
            "price": "666"
        },
        "status": 200
    }
}

2.post接口实例

代码实例

{
    "description": "模拟xx接口,post_form请求和响应,入参是form形式,返回是json数据",
    "request": {
        "headers": {
            "content-type": "application/x-www-form-urlencoded"
        },
        "method": "post",
        "url": "/login",
        "forms": {
            "username": "zhangshan",
            "password": "123456"
        }
    },
    "response": {
        "json": {
            "error_code": 0,
            "reason": "successed",
            "username": "zhangshan",
            "checkstatus": "on"
        },
        "status": 200
    }
}

注意:post中
headers:请求头,根据是form还是json格式的请求来填写
from格式:"content-type": "application/x-www-form-urlencoded"
json格式:"content-type": "application/json"
请求参数格式以及数据,对应headers的content-type
form格式关键字为forms
json格式关键字为json

3.moco框架

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!