关于后端:apipost接口断言详解

1次阅读

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

在做接口测试的时候,会对接口进行断言,一个残缺的接口测试,包含:申请 -> 获取响应注释 -> 断言。

Apipost 官网链接:

Apipost- 基于合作,不止于 API 文档、调试、Mock

一、apipost 如何进行断言

apipost 的断言设置切实后执行脚本中进行编写的。apipost 自身提供了 11 中断言:

apt.assert(‘response.raw.responseText==“test”’); 测试响应内容是否为 test

apt.assert(‘response.raw.status==200’); 测试响应码是否为 200

apt.assert(‘response.raw.type==“json”’); 测试响应内容格局是否为 json

apt.assert(‘response.raw.responseTime>=100’); 测试响应工夫是否大于 100ms

apt.assert(‘response.json.errcode==1’); 测试响应 Json 对象的 errcode 属性是否为 1

apt.assert(‘response.json.errcode!=1’); 测试响应 Json 对象的 errcode 属性是否不为 1

apt.assert(‘response.json.errcode>=1’); 测试响应 Json 对象的 errcode 属性是否为大于等于 1

apt.assert(‘response.json.errcode==null’); 测试响应 Json 对象的 errcode 属性是否为 null

apt.assert(‘response.json.errcode!=null’); 测试响应 Json 对象的 errcode 属性是否不为 null

apt.assert(‘response.headers[“server”] ==“nginx”’); 测试响应头 server 是否为 nginx

apt.assert(‘response.headers[“content-encoding”] ==“gzip”’); 测试响应头 content-encoding 是否为 gzip

二、如何查看断言

接口中查看断言:

流程测试中查看断言:

其中的胜利和失败是代表的流程测试执行胜利了几条执行失败了几条。

三、自定义断言

apipost 脚本反对 js 语句,咱们能够自定义断言,比方:自定义响应值中 json 返回的 code 值是否等于 200

apt.assert(‘response.json.code==200’);

————————————————

版权申明:本文为 CSDN 博主「海淀码农」的原创文章,遵循 CC 4.0 BY-SA 版权协定,转载请附上原文出处链接及本申明。

原文链接:接口测试 –apipost 接口断言详解_海淀码农的博客 -CSDN 博客_接口断言的意思是什么

正文完
 0