4
我正在尝试使用Gatling加载测试Web服务。这是我的build.sbt我如何通过SBT实际运行Gatling测试
import io.gatling.sbt.GatlingPlugin
val gatlingVersion = "2.2.4"
val dependencies = Seq(
"io.gatling" % "gatling-core" % gatlingVersion,
"io.gatling" % "gatling-http" % gatlingVersion
)
lazy val project =
Project("gattling-tests", file("."))
.enablePlugins(GatlingPlugin)
.settings(
javaOptions in Gatling := overrideDefaultJavaOptions("-Xmx4G"),
scalaVersion := "2.12.1",
libraryDependencies ++= dependencies
)
在测试文件夹我创建延伸模拟类,它有我的方案和HTTP请求。
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class ShieldAuthLoadTests extends Simulation {
val httpConf = http
.baseURL("http://localhost:8080/api/1/")
.acceptHeader("application/json")
.contentTypeHeader("json")
val login = http("Login")
.post("login")
.formParam("username", "foo")
.formParam("password", "bar")
.check(status.is(200), jsonPath("$..response.id").ofType[String].saveAs("id"))
val get = http("get")
.get("/api/api1")
.header("token1", "$id")
.check(status.is(200), jsonPath("$..response").exists)
val scn = scenario("scn")
.exec(login)
.pause(3)
.exec(get)
setUp(scn.inject(atOnceUsers(10)).protocols(httpConf))
}
我的希望是,当我会做sbt gatling:test
它会运行gatling测试。但是当我运行sbt gatling:test
它只是在没有运行测试的情况下取得成功。
quickstart说明文件$GATLING_HOME/bin/gatling.sh
但我没有gatling.sh,因为我想通过SBT进行测试。