注意:我是 gatling 新手,对 Scala 几乎一无所知。
我正在开始将我的负载测试从 Jmeter 转换为 gatling。而且我坚持如何组织代码库。我能够找到的所有示例都是单个文件示例。
如何将代码从一个模拟类导入到另一个模拟类?
我现在有这个类和测试场景:
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';
)
}
.....
当我尝试像这样将类导入另一个模拟时:
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._
最佳答案
只是为了让编译器开心,
修改声明:
class createGuestUser extends Simulation
到:
object createGuestUser extends Simulation
然后你可以:
import default.createGuestUser._
模拟不应相互依赖。我会提取公共(public)代码来分离类,例如SimulationSetup, ...场景
关于scala - 如何使用 gatling 将 scala 类导入另一个类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34540818/