karate - 子功能 __arg 的深层副本可能存在错误
问题描述
将 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
推荐阅读
- reactjs - 如何在 ReactJS 中使用 Checkbox 制作树复选框列表?
- ruby - 在 Ruby 中将迭代器转换为数组的单行器
- node.js - 通过 HTTP API 接收部分有效负载 nodejs express 服务
- plsql - 如何在不使用 UTL_FILE 包的情况下将 CLOB 写入 Oracle 中的 OS 文件?
- tensorflow - MultiWorkerMirroredStrategy 在启动 GRPC 服务器后挂起
- javascript - 如何在没有 document.execCommand 的 HTML/JS 中创建 RichText 编辑器?
- c++ - 在 Linux 上构建 ZXing(斑马线)库
- python - KeyError:“[Index(['5', '22', '25', '12',..],\n dtype='object', length=610)] 均不在 [columns] 中”
- c# - UseShellExecute = false 时进程不会退出,但 UseShellExecute = true 时退出
- compiler-construction - 达到定义分析 - 我的解决方案是否正确