四、postman增加断言

预期和实际结果的判断

预期==实际:用例通过,写到报告里

预期!==实际:用例失败,写到报告里

一、例子演示

相当于首页右侧的10大每天的内容

url:http://www.v2ex.com/api/topics/hot.json

Method:GET

Authentication:None

给v2ex的api增加断言

  • 返回的状态码必须是200
  • 返回10条内容
tests["状态码必须是200"] = responseCode.code ===200;

var res= JSON.parse(responseBody);

console.log(res.length);

tests["必须返回10条数据"] = res.length ===10

二、postman的Test功能

  • 设置全局变量
  • 设置环境变量
  • 拿到并处理请求的响应
  • 定义测试检查点和断言
tests["Body is correct"] = responseBody ==="response_body_string";
postman.clearEnvironmentVariable("variable_key");
postman.clearGlobalVariable("variable_key")
tests["Body is correct"] = responseBody ==="response_body_string";
tests["Response time is less than 200ms"] = responseTime < 200;

猜你喜欢

转载自www.cnblogs.com/xinxin1994/p/11258635.html