无法匹配对象数组索引不匹配的相同 json(空手道)

Not able to match same json which has mismatch in indexes of array of objects (Karate)

正在尝试匹配两个 json,但获取测试失败。好吧,两个 json 是相同的,但数组中的对象索引不相同。我认为应该没有什么区别。以下是两个json: 这是代码行:匹配响应包含 ScenarioModelResponse 其中 **回应:**

{
"relationships": [
{
"sourceId": "36",
"targetId": "149",
"type": "Reid Enright"
}
],
"modelId": "027f93d1-ef9e-4f1e-b2c4-684436c5b18a",
"elements": [
{
"externalRefId": "36",
"attributes": {
"jsonPbject": "Reid Enright"
},
"id": "057f7b7e-11b9-4779-97c0-67485153c285",
"type": "Rocky Shore"
},
{
"externalRefId": "149",
"attributes": {
"jsonPbject": "Ben Lyon"
},
"id": "325b989e-b299-4cfc-86b5-0813106da38e",
"type": "Claire Voyance"
}
]
}

场景模型响应:

{
"relationships": [
{
"sourceId": "36",
"targetId": "149",
"type": "Reid Enright"
}
],
"modelId": "027f93d1-ef9e-4f1e-b2c4-684436c5b18a",
"elements": [
{
"externalRefId": "149",
"attributes": {
"jsonPbject": "Ben Lyon"
},
"id": "325b989e-b299-4cfc-86b5-0813106da38e",
"type": "Claire Voyance"
},
{
"externalRefId": "36",
"attributes": {
"jsonPbject": "Reid Enright"
},
"id": "057f7b7e-11b9-4779-97c0-67485153c285",
"type": "Rocky Shore"
}
]
}

这是我在执行后遇到的错误:

    $.elements[0].externalRefId | not equal (STRING:STRING)
    '149'
    '36'

数组不一样。这可以用两行解决:

* match response.relationships == expected.relationships
* match response.elements contains only expected.elements

详细解释参考: