如何使用 gatling 将 scala class 导入另一个?

How can I import a scala class into another using gatling?

注意:我是新手,对 Scala 几乎一无所知。

我正在开始将我的负载测试从 Jmeter 转换为 gatling。而且我坚持如何组织代码库。我能够找到的所有示例都是单个文件示例。

如何将代码从一个模拟 class 导入到另一个?

我现在有这个 class 和测试场景:

    package default

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class createGuestUser extends Simulation {


    val userPrefix = System.getProperty("userPrefix", "gatling_load_test") + "_" + scala.util.Random.nextInt + "_"
    val password = System.getProperty("password", "1234567")
    val hostname = System.getProperty("hostname", "http://0.0.0.0")
    val blank_headers = Map("Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")


    val httpConf = http
        .baseURL("http://0.0.0.0")

    object GetClientToken {     
        val slash = exec(http("Slash")
        .get("/")
        .headers(blank_headers)
        .check(regex("""var appToken = '(.*)';""").find.saveAs("xGlooApplication")) // var appToken = '60e5814d-9271-43b4-8540-157d1c743651';       
        )
    }
.....

当我尝试将 class 导入到另一个类似这样的模拟中时:

    package default

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

import createGuestUser._

class createAccount extends Simulation {

我在尝试导入时遇到以下错误。

08:33:57.952 [ERROR] i.g.c.ZincCompiler$ - /Users/dclements/Dev/Gloo/load_testing/gatling/src/createAccount.scala:9: not found: object createGuestUser 08:33:57.954 [ERROR] i.g.c.ZincCompiler$ - import createGuestUser._

查看官方文档中的advanced tutorial。页面末尾还有一个 link 来源。

只是为了让编译器开心,

修改声明: class createGuestUser extends Simulation

致: object createGuestUser extends Simulation

然后你可以:

import default.createGuestUser._

模拟不应相互依赖。我会提取通用代码来分隔 类 例如模拟设置,...场景