0
点赞
收藏
分享

微信扫一扫

Postman自带的八种断言

yeamy 2022-04-18 阅读 64
postman

 免费的接口地址 控制台 · 天气API (tianqiapi.com)

自己注册一个就可以免费使用

https://yiketianqi.com/api?unescape=1&version=v1&appid=73429187&appsecret=5KAnU3nY

八种断言方式 

// 1.断言返回的返回码为200
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

// 2.断言返回的结果中包含有一个指定的字符串
pm.test("Body matches string", function () {
    pm.expect(pm.response.text()).to.include("city");
});

// 3.对返回的结果做JSON字段检查
pm.test("Your test name", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.cityid).to.eql('101020100');
});
pm.test("Your test name", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.data[0].tem_day).to.eql('19');
});

// 4.断言返回的结果等于一个字符串 一般用于结果固定的接口
pm.test("Body is correct", function () {
    pm.response.to.have.body("返回的结果");
});

// 5.断言响应头中包含有指定的响应头
pm.test("Content-Type is present", function () {
    pm.response.to.have.header("Content-Type");
});

// 6.断言接口请求的时间少于200ms
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});

// 7.断言一个post请求的返回值的状态码是否在指定的范围里面/Status的值在200到202之间
pm.test("Successful POST request", function () {
    pm.expect(pm.response.code).to.be.oneOf([200, 202]);
});

// 8.断言返回的状态码信息中包含指定的字符串
pm.test("Status code name has string", function () {
    pm.response.to.have.status("date");
});
举报

相关推荐

0 条评论