postman常用断言方式

postman(断言) 一、断言 // 断言 =》tests 1、code is 200:断言 http 状态码为 200 pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); 2、contains string:响应报文包含字符串 pm.test("Body matches string", function () { pm.expect(pm.response.text()).to.include("string_you_want_to_search"); }); 3、json value check:检查报文中的 json 值 pm.test("Your test name", function () { var jsonData = pm.response.json(); pm.expect(jsonData.value).to.eql(100); }); 4、is equal to a string:报文等于字符串 var res = {"code":"200","msg":"登录成功!","model":{}} pm.test("Body is correct", function () { pm.response.to.have.body(res); }); 5、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、Successful POST request:断言 post 请求成功,即 http 状态码在列表[201,202]中 pm.test("Successful POST request", function () { pm.expect(pm.response.code).to.be.oneOf([201,202]); });
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!