怎么利用ApiPost接口管理工具校验测试接口返回结果是否符合预期

8次阅读

共计 770 个字符,预计需要花费 2 分钟才能阅读完成。

本文主要讲解接口管理工具 ApiPost 的预执行脚本和后执行脚本里,怎么校验 / 测试接口返回结果是否符合预期?
ApiPost 简介:

ApiPost 是一个支持团队协作,并可直接生成文档的 API 调试、管理工具。它支持模拟 POST、GET、PUT 等常见请求,是后台接口开发者或前端、接口测试人员不可多得的工具。
检测返回 JSON 中的某个值是否等于预期的值

apt.assert(‘response.json.hasOwnProperty(“errcode”)’); // 检测返回 json 对象的是否含有 errcode 字段
apt.assert(‘response.json.errcode==”success”‘); // 检测返回 json 对象的 errcode 字段是否等于 success 字符串
apt.assert(‘response.json.errcode.indexOf(“success”) > -1’); // 检测返回 json 对象的 errcode 字段是否含有 success 字符串
apt.assert(‘response.json.errcode!=”success”‘); // 检测返回 json 对象的 errcode 字段是否不等于 success 字符串
apt.assert(‘response.json.errcode>=1’); // 检测返回 json 对象的 errcode 字段是否大于 1
apt.assert(‘response.json.errcode==null’); // 检测返回 json 对象的 errcode 字段是否是 null

response.json 是什么?

response.json:就是 json 格式的响应数据(上面示例用的就是这个)

调用示例如上面示例:
response.json.data.token // 也可以 response.json.data[“token”]

正文完
 0