注意:我是加特林新手,对 Scala 几乎一无所知。
我正在开始将负载测试从 Jmeter 转换为加特林。我被困在如何组织代码库上。我找到的所有示例都是单个文件示例。
如何将代码从一个模拟类导入到另一个模拟类中?
我现在有这个类和测试场景:
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 [错误] i.g.c.ZincCompiler$ -
/Users/dclements/Dev/Gloo/load_testing/gadling/src/createAccount.scala:9:
未找到:对象 createGuestUser 08:33:57.954 [错误]
i.g.c.ZincCompiler$ - 导入 createGuestUser._
只是为了让编译器高兴,
修改声明:class createGuestUser extends Simulation
to:
object createGuestUser extends Simulation
然后你可以:
import default.createGuestUser._
模拟不应相互依赖。我会将通用代码提取到单独的类中,例如模拟设置,...场景
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)