子功能__arg的深层副本的可能错误

时间:2019-04-10 21:21:18

标签: karate

将json传递给子功能时*复制不会执行深层复制,因此两个实例变量都指向同一数据。

我已经证实*当数据没有传递到子功能时,副本确实很深。

父项功能


  Feature: calling debug feature

    Scenario:
      * def jsonA = { a: "aValue", children: [{childA: "childAValue" }]}
      * def result = call read('Debug.feature') jsonA

子功能

Feature: debug

  Background:
    * def jsonA = __arg
    * copy jsonACopy = jsonA
    * set jsonACopy $.children[0].childA = 'childAValueUpdated'
    * print "TEST: -------------------", jsonA, jsonACopy

    Scenario:
      * match jsonACopy != jsonA

更新jsonACopy之后,我不希望修改jsonA。

15:58:10.517 [main] INFO  com.intuit.karate - [print] TEST: ------------------- {
  "a": "aValue",
  "children": [
    {
      "childA": "childAValueUpdated"
    }
  ]
}
 {
  "a": "aValue",
  "children": [
    {
      "childA": "childAValueUpdated"
    }
  ]
}

15:58:10.519 [main] ERROR com.intuit.karate - assertion failed: path: $, actual: {a=aValue, children=[{"childA":"childAValueUpdated"}]}, NOT expected: {a=aValue, children=[{"childA":"childAValueUpdated"}]}, reason: all key-values matched
15:58:10.520 [main] ERROR com.intuit.karate - feature call failed: Debug.feature
arg: {a=aValue, children=[{"childA":"childAValueUpdated"}]}
Debug.feature:10 - path: $, actual: {a=aValue, children=[{"childA":"childAValueUpdated"}]}, NOT expected: {a=aValue, children=[{"childA":"childAValueUpdated"}]}, reason: all key-values matched
CallDebug.feature:6 -
Debug.feature:10 - path: $, actual: {a=aValue, children=[{"childA":"childAValueUpdated"}]}, NOT expected: {a=aValue, children=[{"childA":"childAValueUpdated"}]}, reason: all key-values matched
HTML report: (paste into browser to view) | Karate version: 0.9.2

1 个答案:

答案 0 :(得分:1)

您可以确认是否与此处打开的问题相同:https://github.com/intuit/karate/issues/708

您还可以在堆栈溢出中参考以下其他答案:https://stackoverflow.com/a/55377608/143475

也请参考上面的未解决问题-如果有任何发现或建议要补充,请发表评论。

目前,请通过执行字符串转换来解决:

* def a = foo
* string b = foo
* json b = b