接口测试-第03天(Postman断言、关联、参数化)

Postman断言

Postman 断言简介

  • 让Postman 工具代替人工 自动判断 预期结果和实际结果是否一致
  • 断言代码 书写在Tests标签页中。查看断言结果 TestResults 标签页

Poatman常用断言

1.断言响应状态码

Status code:Code is 200

//断言响应状态码为 200
pm.test("Status code is 200",function(){
   
    pm.response.to.hava.status(200);
});

pm:postman的实例
test() postman实例的测试方法。这个方法 有2个参数。
    参数1"Status code is 200"。这个参数可以任意修改,不影响断言。
  		作用:在断言结束后,显示给用户,断言结果的提示文字。
    参数2:是一个 匿名函数 调用。

pm.response.to.have.status(200);的意思是:
postman 的响应结果中,应该有 响应状态码 200.---这里的200是预期结果。

接口测试-第03天(Postman断言、关联、参数化)_第1张图片

2.断言包含某字符串

Response body:Contains string

pm.test("Body matches string", function () {
   
    pm.expect(pm.response.text()).to.include<

你可能感兴趣的:(接口测试,postman,测试工具)