Knows Not Much Knows Not Much - 3 months ago 12
Scala Question

Executing Gatling load tests from SBT

I wrote a small web service using Spray framework. I can run it using

sbt run
and then test it in the browser.

Now I wrote a load test using the Gatling framework.

package com.abhi

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class LoadTest extends Simulation {
val httpConf = http
.baseURL("http://localhost:8999")
.acceptHeader("application/json")
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0")

val scn = scenario("BasicSimulation")
.exec(http("request_1")
.get("/path1"))
.pause(5)

setUp(
scn.inject(atOnceUsers(10))
).protocols(httpConf)
}


The test is located in folder
src/test/scala-2.11
and the spray code is in
src/main/scala-2.11


When I run
sbt test
it just prints success without either running my web server or running the test defined above. it just prints success in 3 seconds and gets out.

How can I


  1. ensure that when I do a
    sbt test
    the spray web application is
    started

  2. the galing load test is run against the started server



Edit: I also tried
sbt test scenarios:BasicSimulation
and it threw the error

Not a valid key: BasicSimulation
[error] scenarios:BasicSimulation

Answer

You must use the Gatling sbt plugin to trigger from sbt. Beware that it doesn't run in the default configuration but in the gatling one: gatling:test.

Comments