当前位置:网站首页>Apipost interface assertion details

Apipost interface assertion details

2022-06-24 04:23:00 InfoQ

When doing interface tests , The interface is asserted , A complete interface test , Include : request -> Get the response body -> Assertion .
Apipost The official link :
Apipost- Based on collaboration , More than API file 、 debugging 、Mock​

One 、apipost How to make assertions

apipost After the assertion is set, it is written in the execution script .apipost It provides 11 Break off :
apt.assert(‘response.raw.responseText==“test”’); Test whether the response content is test
apt.assert(‘response.raw.status==200’); Test whether the response code is 200
apt.assert(‘response.raw.type==“json”’); Test whether the response content format is json
apt.assert(‘response.raw.responseTime>=100’); Test whether the response time is greater than 100ms
apt.assert(‘response.json.errcode==1’); Test response Json Object's errcode Whether the property is 1
apt.assert(‘response.json.errcode!=1’); Test response Json Object's errcode Property is not 1
apt.assert(‘response.json.errcode>=1’); Test response Json Object's errcode Property is greater than or equal to 1
apt.assert(‘response.json.errcode==null’); Test response Json Object's errcode Whether the property is null
apt.assert(‘response.json.errcode!=null’); Test response Json Object's errcode Property is not null
apt.assert(‘response.headers[“server”] == “nginx”’); Test response header server Is it nginx
apt.assert(‘response.headers[“content-encoding”] == “gzip”’); Test response header content-encoding Is it gzip
null

Two 、 How to view assertions

Interface to view assertions :
null
View assertions in process testing :
null
Among them, success and failure are the representative of the successful execution of several process tests and the failure of several execution tests .

3、 ... and 、 Custom assertion

apipost
Script support js sentence , We can customize assertions , such as : In the custom response value json Back to code Is the value equal to 200
apt.assert(‘response.json.code==200’);
null
null




————————————————
Copyright notice : This paper is about CSDN Blogger 「 Haidian manong 」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :
The interface test --apipost Interface assertion details _ Haidian Ma Nong's blog -CSDN Blog _ What does an interface assertion mean
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206240032531525.html