How to use the ApiPost interface management tool to verify/test whether the returned result of the interface is as expected?

Posted Jun 5, 20201 min read

This article mainly explains the pre-execution script and post-execution script of the interface management tool ApiPost. How to verify/test whether the interface returns the results as expected?
About ApiPost:

ApiPost is an API debugging and management tool that supports team collaboration and can directly generate documents. It supports simulating common requests such as POST, GET, PUT, etc. It is a rare tool for background interface developers or front-end and interface testers.
Check if a value in the returned JSON is equal to the expected value

apt.assert('response.json.hasOwnProperty("errcode")'); //Check whether the returned json object contains the errcode field
apt.assert('response.json.errcode=="success"'); //Check whether the errcode field of the returned json object is equal to the success string
apt.assert('response.json.errcode.indexOf("success")> -1'); //Check whether the errcode field of the returned json object contains a success string
apt.assert('response.json.errcode!="success"'); //Check whether the errcode field of the returned json object is not equal to the success string
apt.assert('response.json.errcode>=1'); //Check whether the errcode field of the returned json object is greater than 1
apt.assert('response.json.errcode==null'); //Check whether the errcode field of the returned json object is null

What is response.json?

response.json:is the response data in json format(this is the example used above)

The calling example is as the above example:
response.json.data.token //Also available response.json.data["token"]