子功能的深层复制可能存在错误 __arg
Possible bug with deep copy of subfeature __arg
当将 json 传递给子功能时 * copy 不执行深层复制,因此两个实例变量都指向相同的数据。
我已经验证 * 当数据没有传递给子特征时副本确实很深。
父特征
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 上的其他答案:
另请参阅上面的未解决问题 - 如果您有任何发现或建议要添加,请发表评论。
现在,请通过进行字符串转换来解决问题:
* def a = foo
* string b = foo
* json b = b
当将 json 传递给子功能时 * copy 不执行深层复制,因此两个实例变量都指向相同的数据。
我已经验证 * 当数据没有传递给子特征时副本确实很深。
父特征
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 上的其他答案:
另请参阅上面的未解决问题 - 如果您有任何发现或建议要添加,请发表评论。
现在,请通过进行字符串转换来解决问题:
* def a = foo
* string b = foo
* json b = b