karate - 空手道:是否可以比较两个服务响应并在比较中排除一些键
问题描述
我正在尝试使用空手道比较来自两个服务调用(用于迁移项目)的响应。对于以下情况,是否可以在一次比较整个响应时排除或忽略某些键:
1)响应值不同的元素很少(以粗体标记)。2)很少有元素不存在于一个响应中但存在于另一个响应中(以粗体标记)。
服务 1 响应 -
{
"userKey": "string",
"enabled": true,
"locked": true,
"profile": {},
"roles": [
{
"roleKey": 3,
"name": "Role",
**"links": []**
}
],
"links": [
{
"rel": "self",
**"href": "https://starhub1.com"**
},
{
"rel": "self",
**"href": "https://singtel1.com"**
}
]
}
服务 2 响应 -
{
"userKey": "string",
"enabled": true,
"locked": true,
"profile": {},
"roles": [
{
"roleKey": 3,
"name": "Role"
}
],
"links": [
{
"rel": "self",
**"href": "https://starhub22.com"**
},
{
"rel": "self",
**"href": "https://singtel22.com"**
}`enter code here`
]
}
解决方案
是的,空手道在这方面做得很好。只需在比较之前对一个有效负载进行转换。
有关详细信息,请参阅此答案:https ://stackoverflow.com/a/53120851/143475
对于您的特定示例,您可能需要做的就是将“一侧”更改为#string
然后进行比较。
* def response1 = { foo: 'hello' }
* def response2 = { foo: 'world' }
* response2.foo = '#string'
* match response1 == response2
推荐阅读
- java - 为什么同步的 getter 像 volatile 读取一样工作?
- javascript - 循环按钮和警报值
- vsto - 安装屏蔽项目需要做什么才能使其能够卸载已安装的 Word 加载项
- python - 根据其他行更新熊猫数据框的行
- html - 仅使用 CSS 和 HTML 设置特定 div 的样式,尽管它位于 div 中的许多 div 中
- google-sheets - 如果对象在某个时间范围内,则从时间范围/条件格式创建日历
- javascript - 通过 Twilio Studio 将消息从 WhatsApp 推送到 Twilio Flex 会导致架构验证警告 12200
- api - 使用 api 在 shopify 中添加客户的问题
- ios - MLKit iOS:架构 armv7 的未定义符号
- gtk - Julia + GTK - 回调中的全局变量更改