How do I actually run the Gatling test via SBT
Asked Answered
S

2

8

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.

Stereotype answered 5/4, 2017 at 16:15 Comment(0)
A
7

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.

Analogical answered 5/4, 2017 at 19:43 Comment(0)
M
1

Check that your simulations are created in the src/test/scala folder, see https://gatling.io/docs/3.0/extensions/sbt_plugin/#default-settings

Mind answered 10/12, 2018 at 9:4 Comment(1)
Links may become obsolete. Try to add the main points of the link in your answer so it's self sufficient.Bibliographer

© 2022 - 2024 — McMap. All rights reserved.