文章例子返回结果
{
"code": 1,
"msg": "",
"data": {
"area_info": {
"area_id": 70966,
"area_type": 2,
"name": "渝北",
"pinyin_url": "yubei",
"county_id": null
}
}
}
1、判断请求返回的状态为200,200正常
或者使用
tests[“Status code is 200”] = responseCode.code == 200;
2、判断请求返回中其它字段的值(或状态)
3、获取json数据,并校对返回值的正确性
根据json数据结构获取数据与实际值做对比
//判断返回json中是否含有该字段
pm.test(“Body is correct”, function () {
pm.response.to.have.jsonBody(“data.area_info.area_type”);
});
4、判断响应时间
5、判断返回数据的类型
var res=JSON.parse(responseBody);
tests[“判断area_id的值的类型是否是number”] = typeof(res.data.area_info.area_id) === “number”;
// 比较常用的集中类型:number、string、object、array、boolean、undefined
//6、判断返回数据中是否存在某个元素
tests[‘判断返回的元素中是否有data’]=responseBody.has(‘data’)