Postman[8] 断言

1.常见的断言类型

status code: code is 200 //检查返回的状态码是否为200

Response body: contain string //检查响应中包含指定字符串包含指定的值

response body:json value check/ /检查响应中其中json的值

Response body: is equal to string //检查响应等于一个字符串

Response header:contend-type //检查是否包含响应头

Response time is less than 200ms //检查请求耗时小于200ms

进入Test,右侧有提供断言的类型:

2.断言使用的全局变量

断言使用的全局变量可以参考:

Postman[6] 返回结果中提取并设置全局变量-CSDN博客

3.断言例子

url: https://www.baidu.com

复制代码
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("百度一下");
});
pm.test("Content-Type is present", function () {
    pm.response.to.have.header("Content-Type");
});
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});

4.全局断言及批量处理

4.1设置全局断言,规则和上面一样

4.2Run(运行)

4.3选取需要运行的请求并运行

4.4运行结果

相关推荐
会算数的⑨3 分钟前
Spring AI Alibaba 学习(三):Graph Workflow 深度解析(下篇)
java·人工智能·分布式·后端·学习·spring·saa
chilavert3186 分钟前
技术演进中的开发沉思-367:锁机制(上)
java·开发语言·jvm
BigGGGuardian16 分钟前
写了个 Spring Boot 防重复提交的轮子,已发到 Maven Central
java
hewence116 分钟前
协程间数据传递:从Channel到Flow,构建高效的协程通信体系
android·java·开发语言
哈库纳21 分钟前
dbVisitor 利用 queryForPairs 让键值查询一步到位
java·后端·架构
野犬寒鸦31 分钟前
CompletableFuture 在 项目实战 中 创建异步任务 的核心优势及使用场景
java·服务器·后端·性能优化
Java小卷33 分钟前
Drools kmodule 与 ruleunit 模块用法详解
java·后端
程序员敲代码吗34 分钟前
虚拟机内部工作机制揭秘:深入解析栈帧
java·linux·jvm
小钻风336635 分钟前
Spring MVC拦截器的快速应用
java·spring·mvc
wsfk123437 分钟前
总结:Spring Boot 之spring.factories
java·spring boot·spring