Gatling - 如何从包中导入对象

Gatling - How to import objects from packages

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