【问题标题】:I want to write test case in postman to validate below test case我想在邮递员中编写测试用例来验证下面的测试用例
【发布时间】:2021-10-04 05:54:04
【问题描述】:

我想验证材料 ID 的长度为“14”且材料部门为“OT”

在邮递员中为以下 JSON 响应编写什么测试用例。

{
  "success": "true",
  "Result": {
    "Response": [
      {
        "Material Id": "e838663839398f",
        "Material Department": "OT"
      }
    ]
  }
}

【问题讨论】:

标签: json postman web-api-testing postman-testcase


【解决方案1】:

你可以这样写测试

const res = pm.response.json();

pm.test("check id", () => {
    const id = res.Result.Response[0]["Material Id"];
    pm.expect(id.length).to.eql(14);
});


pm.test("check Department", () => {
    const dep = res.Result.Response[0]["Material Department"];
    pm.expect(dep).to.eql("OT");
});

【讨论】:

  • {"Success" : true, "message" : "" ,"Statuscode" : 200 , "Result" : [{"Value" : "F33344555656565" "Text" : "Accident" "Criteria " : "TTL" }] } 我想验证 Values 的长度为“15”,Text 的长度为“Accident as Values”
  • lucasnguyen17 提供的答案应该足以满足您的第二个要求。
  • 我想你可以看到我的回答并找出处理类似问题的方法。
  • @lucasnguyen17 如果我输入长度为“20”而不是“14”,则测试用例长度未得到验证,那么测试用例也通过了,如果我输入“0”,测试用例甚至通过而不是“14”
  • @ViditYadav 您是否在运行测试之前保存了更改?在发布答案之前我已经测试过了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多