繁体   English   中英

如何使用响应正文作为结果让我的 Postman 测试通过?

[英]How do I get my Postman tests to pass using response body as the results?

我第一次尝试在 Postman 中编写测试。 我正在使用包含pm.expectpm.test方法。

这是我的测试:

//contract details tests
pm.test("Contract data is correct", function() {
        pm.expect(pm.response.json().results.contractNb).to.equal("00002");
        pm.expect(pm.response.json().results.progSrvcNm).to.equal("009");
});

我的回答是这样的:

{
    "contractNb": "00002",
    "progSrvcNm": "009",
    "contractPartyNm": "testContract",
    "terms": 30,
    "startDt": "2018-01-01"
}

给定您的响应正文数据 - 如果您只是删除expect语句的.results部分,则检查将通过。

pm.test("Contract data is correct", () => {
    pm.expect(pm.response.json().contractNb).to.equal("00002")
    pm.expect(pm.response.json().progSrvcNm).to.equal("009")
})

邮差

正确的代码是 Danny Dainton 发布的。

pm.test('Contract details are correct for the passed in contract ID', () => {
    pm.expect(pm.response.json().contractNb).to.equal("00002");
    pm.expect(pm.response.json().progSrvcNm).to.equal("009");
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM