apipost接口断言详解

90 阅读1分钟

在做接口测试的时候,会对接口进行断言,一个完整的接口测试,包括:请求->获取响应正文->断言。

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博客_接口断言的意思是什么