将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
你能否确认这是否与此处打开的问题相同:https://github.com/intuit/karate/issues/708
您还可以参考Stack Overflow上的其他答案:https://stackoverflow.com/a/55377608/143475
另请参阅上面的未解决问题 - 如果您有任何要添加的发现或建议,请进行评论。
现在,请通过执行字符串转换来解决此问题:
* def a = foo
* string b = foo
* json b = b