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

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

问题描述

我在邮递员中进行了测试,响应返回的是嵌套"数据.我的意思是我们有响应的数据"部分和消息"部分.内部数据还有大量其他字段,这些是我需要使用 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";

这是我在 postman 中的设置以及相应的 json 响应:

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

这是我的测试结果:

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

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