postman实战之断言

断言脚本事例

pm.test("校验状态码为200", function () {
    pm.response.to.have.status(200);
});

pm.test("校验响应特中是否包含某个字符串", function () {
    pm.expect(pm.response.text()).to.include("恭喜你  登陆成功");
});

pm.test("校验测试用例中json的值", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.data.age).to.eql(20);
});

pm.test("校验测试用例响应全等于某个字符串", function () {
    pm.response.to.have.body({"msg":"恭喜你  登陆成功","code":0,"data":{"city":"中国","identity":"学员","sex":"女","name":"anna小姐姐","age":20}});
});

pm.test("校验响应的头信息中是否包含某个值", function () {
    pm.response.to.have.header("Content-Type");
});

pm.test("校验响应的时长", function () {
    pm.expect(pm.response.responseTime).to.be.below(8);
});

pm.test("是否包含响应的状态码", function () {
    pm.expect(pm.response.code).to.be.oneOf([201, 202,200]);
});

pm.test("如果响应状态码包含某个字符串的话,就执行成功", function () {
    pm.response.to.have.status("OK");
});

  

查看测试是否通过

原文地址:https://www.cnblogs.com/joy-sir/p/14649849.html