Postman断言

断言:用于判断接口请求是否成功!

最少两个:

状态断言:200

业务断言:可以有多个。

 

//状态断言:

//断言状态码为200

pm.test("Status code is 200", function () {

pm.response.to.have.status(200);

});

//业务断言

//断言返回的结果中包含一个字符串

pm.test("Body matches string", function () {

pm.expect(pm.response.text()).to.include("access_token");

});

//检查返回的JOSN数据的值。

pm.test("Your test name", function () {

var jsonData = pm.response.json();

pm.expect(jsonData.expires_in).to.eql(7200);

});

//断言返回的结果等于一个字符串

pm.test("Body is correct", function () {

pm.response.to.have.body("{"errcode":0,"errmsg":"ok"}");

});

//断言响应头中是否包含Content-Type

pm.test("Content-Type is present", function () {

pm.response.to.have.header("Connection");

});

//断言接口的请求时间少于200ms

pm.test("Response time is less than 200ms", function () {

pm.expect(pm.response.responseTime).to.be.below(200);

});

原文地址:https://www.cnblogs.com/wangfan9/p/13468387.html