调用空手道功能文件 returns 响应对象,包括父场景的先前响应对象的多个副本

Calling Karate feature file returns response object including multiple copies of previous response object of parent scenario

我正在研究执行复杂场景时堆大小 JAVA 的指数增长,尤其是在多个可重用场景中。这是我尝试通过简单的示例和对 JVM 堆使用的可能解释来解决问题。

环境:空手道 1.1.0.RC4 | JDK 14 | Maven 3.6.3

示例:下载project, extract and execute maven command as per READEME

观察:按照下面的例子,如果我们多次调用同一个场景,响应对象会呈指数增长,因为它包括来自先前调用场景的响应以及全局变量的副本。

  @unexpected
  Scenario: Not over-writing nested variable
    * def response = call read('classpath:examples/library.feature@getLibraryData')
    * string out = response
    * def resp1 = response.randomTag
    * karate.log('FIRST RESPONSE SIZE = ', out.length)

    * def response = call read('classpath:examples/library.feature@getLibraryData')
    * string out = response
    * def resp2 = response.randomTag
    * karate.log('SECOND RESPONSE SIZE = ', out.length)

Output:
10:26:23.863 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 9 by tag: getLibraryData
10:26:23.875 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 14 by tag: libraryData
10:26:23.885 [main] INFO  com.intuit.karate - FIRST RESPONSE SIZE =  331 
10:26:23.885 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 9 by tag: getLibraryData
10:26:23.894 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 14 by tag: libraryData
10:26:23.974 [main] INFO  com.intuit.karate - SECOND RESPONSE SIZE =  1783 
10:26:23.974 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 9 by tag: getLibraryData
10:26:23.974 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 14 by tag: libraryData
10:26:23.988 [main] INFO  com.intuit.karate - THIRD RESPONSE SIZE =  8009 
  1. 我们真的需要在调用功能文件(非共享范围)的响应中包含响应和全局变量吗?
  2. 当我们读取大型 json 文件并调用多个可重用场景文件时,每次读取 json 数据的副本都会添加到响应对象中。有没有办法避免这种行为?
  3. 是否有更好的方法来使用可重用场景编写复杂测试脚本,而无需相同变量的多个副本?

好的,你能看看这个问题吗:

https://github.com/intuit/karate/issues/1675

我同意我们可以优化响应和全局变量。如果你能贡献代码就太好了。