加特林 - 如何从包导入对象



我希望有一个包含 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

这是对的吗?我错过了什么吗?

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

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

您可以将包导入为:

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

最新更新