zoukankan      html  css  js  c++  java
  • Postman断言

    1、断言:让程序判断预期结果和实际结果是否一致。

    (1)特点

    • Postman的断言是使用JavaScript语言编写的,写在Tests标签页里
    • Tests中的脚本在发送请求之后执行,会把断言的结果(PASS/FAIL)最终在Test Results标签页中展示

    (2)常用断言

    • Status code:Code is 200      //判断响应状态码是否等于200
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    });
    • Response body:Contains string    //判断响应体中是否包含指定的字符串
    pm.test("Body matches string", function () {
        pm.expect(pm.response.text()).to.include("string_you_want_to_search");
    });
    • Response body:Is equal to a string    //判断响应体是否完成等于某个字符串
    pm.test("Body is correct", function () {
        pm.response.to.have.body("response_body_string");
    });
    • Response body:JSON value check    //校验响应的json数据
    pm.test("Your test name", function () {
        var jsonData = pm.response.json();
        pm.expect(jsonData.value).to.eql(100);
    });
    • Response headers:Content-Type header check  //断言响应头信息
    pm.test("Content-Type is present", function () {
        pm.response.to.have.header("Content-Type");
    });

     

  • 相关阅读:
    从 PHP 到 Java
    用Lua定制Redis命令
    见招拆招-PostgreSQL中文全文索引效率优化
    通过2-3-4树理解红黑树
    代码迁移之旅(二)- 渐进式迁移方案
    多线程编程
    Gotorch
    使用PostgreSQL进行中文全文检索
    代码重构之旅(一) 项目结构
    Linux“体检”指标
  • 原文地址:https://www.cnblogs.com/wangzicong/p/15654964.html
Copyright © 2011-2022 走看看