scalagatling

How do I actually run the Gatling test via SBT


I am trying to load test a 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 which extends Simulation and it has my scenario 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))
}

My hope was that when I will do sbt gatling:test it will run the gatling test. but when I run sbt gatling:test it just comes out with success without running the test.

the quickstart documentation says $GATLING_HOME/bin/gatling.sh but I don't have the gatling.sh because I want to test via SBT.


Solution

  • The docs are a little inconsistent as I've run into similar issues.

    I always base my project on this just to be sure.

    Anyway it looks like an issue with your dependencies. Try changing them to this instead...

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

    Or see here.