karate - 空手道模式验证,在使用匹配包含断言时它是否适用于嵌套数组?
问题描述
我试图通过仅检查某些元素来对 json 对象使用匹配项。Json 对象包含一个嵌套数组,这似乎是测试失败的根本原因。似乎在嵌套数组中的 key:values 上使用“匹配包含”断言无法按预期工作并引发错误。
我尝试在第一级键上使用“匹配包含”并且效果很好,但是当尝试匹配嵌套数组中的键时,我收到以下错误消息:原因:实际值比预期多 1 个键
* def json = { id: 1, priority: 1, compRound: { id: 1, comp_id: 89 } }
* match json contains
"""
{
id: '#number',
priority: '#number',
compRound: {
id: '#number'
}
}
"""
当我使用match contains
断言时,我希望测试能够通过,但看起来空手道希望嵌套数组中的所有键:值都存在。
解决方案
请仔细阅读文档的这一部分:https ://github.com/intuit/karate#contains-short-cuts
* def json = { id: 1, priority: 1, compRound: { id: 1, comp_id: 89 } }
* def compRound = { id: '#number' }
* match json == { id: '#number', priority: '#number', compRound: '#(^compRound)' }
推荐阅读
- sql - 如何在一个查询SQL中更新一列中的多行
- c - 如何在C中获取子进程PID
- javascript - 使用一个全局函数检查多个复选框
- javascript - 检查是否至少选中了一个 RADIO BUTTON
- spring - 如何使用 Spring Security 读取 CAS 票证验证 XML?
- rcpp - 在 Rcpp 函数中将类作为参数传递
- python - 如何在kivy中制作和设计我们的自定义数据表
- .net - 使用 XmlSerializer.Serialize 时是否可以丢弃在序列化期间引发错误的元素?
- networking - TCP计算校验和
- python-3.x - 使用 BeautifulSoup 从网站下载特定文件