邮递员喷气背包-测试嵌套数据 [英] postman jetpacks - testing for nested data

查看:136
本文介绍了邮递员喷气背包-测试嵌套数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在邮递员中进行了一次测试,并且回复返回了嵌套"数据.我的意思是说,我们在响应中有一个数据"部分,在消息"中有一个部分.内部数据中还有很多其他字段,这些是我需要在Jetpacks上进行验证的字段.我怎么去这些领域?

I have a test in postman and the response comes back with 'nested' data. By that I mean we have a 'data' section of the response and a 'messages' section. Inside data there are a ton of other fields and those are the ones I need to be verifying on with Jetpacks. How can I get to these fields?

这是json响应的样子:

this is what the json response looks like:

{
  "Data": {
    "QRCode_ID": 168,
    "Repairer_ID": null,
    "AssignedToEmployee_ID": null,
    "TaskName": "003021919913",
    "DueDate": "2015-07-02T00:12:53.597",
    "DueDateTimeSpan": 1959471956224,
    "TaskStatus_ID": 1,
    "Description": "due 6/30, 5:00",
    "TaskUrgency_ID": null,
    "TaskType_ID": null,
    "DueDateDisplay": "2015-07-02 00:12",.......
      }
  },
  "Messages": [
    "success"
  ]
}

这就是我的邮递员考试的样子:

And this is what my postman test looks like:

var data = JSON.parse(responseBody);
tests["Verify QRCode_ID is correct"] = data.QRCode_ID === 168;

推荐答案

您可以使用与测试未嵌套的数据相同的方式来测试嵌套数据(使用点表示法)

You can test for nested data much in the same way you test for data that is not nested (using dot notation)

我创建了一个非常快速的虚拟服务,该服务返回以下json:

I created a really quick dummy service that returns the the following json:

{
  "one": "1",
  "two": "2",
  "three": {
    "four": "4",
    "five": "5"
  }
}

在以下代码段中,我测试(使用点表示法)嵌套对象中的值.特别是我断言对象3具有分别设置为"4"和"5"的值的属性4和5:

In the following snippet I test (using dot notation) values in the nested object. In particular I'm asserting that the object three has properties of four and five that are set to the values of "4" and "5" respectively:

var data = JSON.parse(responseBody);
tests["4"] = data.three.four === "4";
tests["5"] = data.three.five === "5";

这是我在邮递员中的设置,带有相应的json响应:

Here's my setup in postman with the corresponding json response:

这是我的测试结果:

Here are my test results:

这篇关于邮递员喷气背包-测试嵌套数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆