【问题标题】:Test a big body response in JSON on Postman在 Postman 上测试 JSON 格式的大体响应
【发布时间】:2021-06-22 17:36:53
【问题描述】:

我有一个关于 Postman 的正文回复,该回复为我返回:

[
{
    "key": "Dateline Standard Time",
    "value": "(UTC-12:00) International Date Line West"
},
{
    "key": "UTC-11",
    "value": "(UTC-11:00) Coordinated Universal Time-11"
},
{
    "key": "Aleutian Standard Time",
    "value": "(UTC-10:00) Aleutian Islands"
}]

那么,在“测试”选项卡中,我应该写什么来测试响应是否完全按照相同的顺序?

我尝试过这样的事情:

    pm.test("Body is correct", function(){
      pm.response.to.have.body("
     [
    {
        "key": "Dateline Standard Time",
        "value": "(UTC-12:00) International Date Line West"
    },
    {
        "key": "UTC-11",
        "value": "(UTC-11:00) Coordinated Universal Time-11"
    },
    {
        "key": "Aleutian Standard Time",
        "value": "(UTC-10:00) Aleutian Islands"
    }]
    ");

但还是不行。

谢谢!

【问题讨论】:

    标签: api testing postman postman-testcase


    【解决方案1】:
    pm.test("Body is correct", function () {
        pm.expect(pm.response.json()).to.deep.equal(
            [
                {
                    "key": "Dateline Standard Time",
                    "value": "(UTC-12:00) International Date Line West"
                },
                {
                    "key": "UTC-11",
                    "value": "(UTC-11:00) Coordinated Universal Time-11"
                },
                {
                    "key": "Aleutian Standard Time",
                    "value": "(UTC-10:00) Aleutian Islands"
                }]
        )
    });
    

    使用深度相等

    【讨论】:

      猜你喜欢
      • 2019-05-18
      • 2018-09-10
      • 2019-01-25
      • 2020-12-16
      • 1970-01-01
      • 1970-01-01
      • 2021-02-28
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多