这是我的输入
{
"AccountId": "9834e8cb-275a-4bff-b362-f216e9653686",
"ContactId": "9834e8cb-275a-4bff-b362-f216e9653686",
"AuthenticationDetails": {
"AuthenticationId": "{{clientId}}",
"AuthenticationType": "Token"
}
}这是我的输出
{
"orderedByContactId": "36b8e4da-94fd-4680-a2d3-6b128e4b2584",
"orderedForContactId": "9834e8cb-275a-4bff-b362-f216e9653686"
}我需要创建一个测试(postman)来确保输出值("orderedForContactId")与输入值("ContactId")匹配。有人能帮帮我吗?
现有测试的格式如下:
pm.test("Response should contain orderedForContactId",function(){
let jsonRespData = pm.response.json();
pm.expect(jsonRespData).to.have.property('orderedForContactId');
});发布于 2020-02-26 21:34:58
使用该脚本作为测试脚本
pm.test("Response should contain orderedForContactId",function(){
var requestJson= JSON.parse(pm.request.body.raw);
var contactId = requestJson.ContactId.toString();
var responseJson = pm.response.json();
var orderedForContactId = responseJson.orderedForContactId;
pm.expect(orderedForContactId ).to.equal(contactId);
});发布于 2020-02-26 23:10:13
我将输入更改为
{
"AccountId": "9834e8cb-275a-4bff-b362-f216e9653686",
"ContactId": "{{ContactId}}",
"AuthenticationDetails": {
"AuthenticationId": "{{clientId}}",
"AuthenticationType": "Token"
}
}并将ContactId添加到环境文件中。然后我创建了下面的测试:
pm.test("Input ContactId should equal orderedForContactId",function(){
let jsonRespData = pm.response.json().orderedForContactId;
pm.expect(jsonRespData).to.equal(pm.environment.get("ContactId"))
});https://stackoverflow.com/questions/60397311
复制相似问题