how to make a copy of the result of a call

假装没事ソ 提交于 2019-12-13 18:17:04

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!