How can I run a gatling test via SBT

I am trying to download a test web service using Gatling. this is my build.sbt

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
      )

Under the tests folder, I created a class that extends Simulation, and it has my script and http requests.

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))
}

I was hoping that when I did, sbt gatling:testhe would run the gatling test. but when I run sbt gatling:testit just works successfully without running the test.

Quickstart documentation says $GATLING_HOME/bin/gatling.sh, but I do not have gatling.sh, because I want to check through SBT.

+5
source share
2 answers

The docs are a bit inconsistent as I ran into similar issues.

, .

. ...

val dependencies = Seq(
  "io.gatling.highcharts" % "gatling-charts-highcharts" % "2.2.4" % "test,it",
  "io.gatling"            % "gatling-test-framework"    % "2.2.4" % "test,it"
)

. .

+5

Source: https://habr.com/ru/post/1674117/


All Articles