how to make a copy of the result of a call

2019-08-09 11:41发布

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"

标签: karate
1条回答
2楼-- · 2019-08-09 12:08

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"
查看更多
登录 后发表回答