随笔 - 8  文章 - -1  评论 - 0  阅读 - 7882

Postman的断言

一、postman的断言模块

1、postman提供封装好的断言脚本,位置如图:

2、全局断言

二、常用断言

1、简单的业务断言
1)Status code:Code is 200 检查返回状态码是否为200;

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

2)Response body:Contains string 检查响应中是否包含指定字符串;

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

3)Response body:Json value check 检查响应中json的值;

pm.test("Your test name", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.value).to.eql(100);
});

4)Response body:is equal to a string 检查响应是否等于一个字符串;

pm.test("Body is correct", function () {
    pm.response.to.have.body("response_body_string");
});

5)Response headers:Content-Type header check 检查是否包含响应头Content-Type;

pm.test("Content-Type is present", function () {
    pm.response.to.have.header("Content-Type");
});

6)Response time is less than 200ms 检查请求耗时是否小于200ms;

pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});

7)Status code :Successfull POST request 判断post请求的状态码是否在201和202中;

pm.test("Successful POST request", function () {
    pm.expect(pm.response.code).to.be.oneOf([201, 202]);
});
posted on   一只小蜗  阅读(61)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示