如何在比较两个JSON时列出所有差异

时间:2019-01-22 16:32:19

标签: karate

这是我的代码。

*  def aJson = [{foo1:2}, {bar1:2} , {foo2:null}, {bar2:a}]
*  def bJson = [{foo1:4}, {bar1:2} , {foo2:null}, {bar2:b}];
*  match aJson == bJson

响应为.. com.intuit.karate.exception.KarateException:Elimination.feature:25-路径:$ [0],实际:{foo1 = 2},预期:{foo1 = 4},原因:[path:$ [0],实际:{foo1 = 2},预期:{foo1 = 4},原因:所有键值都不匹配]

我想列出所有差异为:

com.intuit.karate.exception.KarateException: Elimination.feature:25 - path: $[0], actual: {foo1=2}, expected: {foo1=4}, reason: [path: $[0], actual: {foo1=2}, expected: {foo1=4}, reason: all key-values did not match]

实际:{foo1 = 2},预期:{foo1 = 4}, 实际:{bar2:a},预期:{bar2:b}

1 个答案:

答案 0 :(得分:1)

Karate version: 0.9.1
======================================================
elapsed:   0,27 | threads:   10 | thread time: 0,04 
features:     1 | ignored:    1 | efficiency: 0,01
scenarios:    1 | passed:     0 | failed: 1
======================================================
failed features:
examples.users.test: test.feature:7 - path: $[0], actual: {foo1=2}, expected: {foo1=4}, reason: [path: $[0].foo1, actual: 2, expected: 4, reason: not equal (Integer)]

这是您的0.9.1版代码的结果,此错误为此提供了错误修复。 据我所知,将无法获得有关foo1bar2错误的信息。