【问题标题】:Gatling - How to import objects from packagesGatling - 如何从包中导入对象
【发布时间】:2019-11-22 18:16:53
【问题描述】:

我希望有一个包含 util 变量的文件,以便在我的模拟类中重用,但出现以下错误:

18:15:22.702 [ERROR] i.g.c.ZincCompiler$ - /app/simulations/keyword_search/test.scala:9:20: object Args is not a member of package simulations
import simulations.Args._
                   ^
18:15:22.711 [ERROR] i.g.c.ZincCompiler$ - /app/simulations/keyword_search/test.scala:12:13: not found: value name
    println(name)
            ^
18:15:22.726 [ERROR] i.g.c.ZincCompiler$ - two errors found
18:15:22.740 [ERROR] i.g.c.ZincCompiler$ - Compilation crashed

我有以下场景:

项目路径:

simulations/
--keyword_search/
----test.scala
--args.scala

simulations/args.scala 文件:

package simulations

object Args {
  val name = "bla"
}

simulations/keyword_search/test.scala 文件:

package simulations.keyword_search

import simulations.Args._

class Test extends Simulation {
  print(name)
}

我正在使用以下脚本运行 gatling

gatling -sf /app/simulations/keyword_search -s simulations.keyword_search.Test

这是正确的吗?我错过了什么吗?

【问题讨论】:

    标签: scala gatling


    【解决方案1】:

    Gatling 不知道args.scala,因为该文件位于指定为模拟文件夹-sf 的目录之外。 请使用 /app/simulations 作为模拟文件夹运行您的 Gatling 模拟:

    gatling -sf /app/simulations -s simulations.keyword_search.Test
    

    【讨论】:

      【解决方案2】:

      您可以将包导入为:

      import users._  // import everything from the users package
      import users.User  // import the class User
      import users.{User, UserPreferences}  // Only imports selected members
      import users.{UserPreferences => UPrefs}  // import and rename for convenience
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-11-23
        • 2022-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-18
        • 2020-08-20
        相关资源
        最近更新 更多