使用空手道,我正在尝试匹配两个不当订单的JSON阵列

  • 本文关键字:两个 阵列 JSON 空手道 karate
  • 更新时间 :
  • 英文 :


e.g。

* def products = [{"ProductCode":"a","UnitPrice":100.0},{ {"ProductCode":"b","UnitPrice":200.0}]
* def inventory = [{"ProductCode":"b","UnitPrice":200.0},{ {"ProductCode":"a","UnitPrice":100.0}]
* match products == inventory

这失败了,因为数组中元素的顺序与不匹配。我如何告诉空手道忽略订单?

您真的应该阅读文档:https://github.com/intuit/karate#match-contains

* def products = [{"ProductCode":"a","UnitPrice":100.0},{"ProductCode":"b","UnitPrice":200.0}]
* def inventory = [{"ProductCode":"b","UnitPrice":200.0},{"ProductCode":"a","UnitPrice":100.0}]
* match products contains only inventory

匹配操作很明智,因为白空间无关紧要,键(或数据元素)的顺序无关紧要。空手道甚至能够忽略您选择的字段 - 当您要动态生成的服务器端时,例如UUID-S,Time-Spamps,SecurityTokens等非常有用。

匹配语法涉及双等符号'=='表示比较(而不是分配'=')。

最新更新