问题
Why does the following test not pass? I must be missing something fundamental about how copy works. It seems to have a reference to the json object and not a copy.
Feature: testing
@one
Scenario: one
* def root = { name: 'inner' }
Scenario: two
* def a = call read('testing.feature@one')
* copy b = a
* set b.root.name = "copy"
* match b.root.name == "copy"
* match a.root.name == "called"
回答1:
Always un-wrap the results of call
. The reason is that particular JSON object is "special" (a Java map) which does not follow the rules of copy
- because you can have references to other Java objects. So this will work:
@one
Scenario: one
* def root = { name: 'inner' }
Scenario: two
* def temp = call read('dev.feature@one')
* def a = temp.root
* copy b = a
* set b.name = "copy"
* match b.name == "copy"
* match a.name == "inner"
来源:https://stackoverflow.com/questions/55377162/how-to-make-a-copy-of-the-result-of-a-call