Gatling — SBT For Load Testing

Knoldus Inc.
Knoldus - Technical Insights
2 min readJul 14, 2015

Gatling is an open source load testing framework based on Scala, Akka and Netty and ready our self for load testing. Load testing is performed to determine a system’s behaviour under both normal and at peak conditions.

The aim includes;

  • High performance
  • Ready-to-present HTML reports
  • Scenario recorder and developer-friendly DSL

Setup:

1. In project/plugins.sbt, add:

[code]
addSbtPlugin(“io.gatling” % “gatling-sbt” % “2.1.6”)
[/code]

Also needs to add these two dependencies in build.sbt:

[code]
enablePlugins.GatlingPlugin
libraryDependencies += “io.gatling.highcharts” % “gatling-charts-highcharts” % “2.1.6” % “test”
libraryDependencies += “io.gatling” % “gatling-test-framework” % “2.1.6” % “test”
[/code]

DSL:

A Simulation is a real Scala class containing 4 different parts:
http:
we can define the baseURL, which will be prepended to all the relative paths in the scenario definition. Also we can define some other configurations such as common headers, user agent etc, which will be added on each request.

header:
we define the headers which can be used for each request that will be sent to the server.

scenario:
This is the main part of your test. It has a sequence of exec commands. Each exec command is used to execute a set of actions(GET, POST, etc.) that will be executed in order to simulate.

simulation:
This is usually the last part of the test script. This is where we define the load we want to inject to your server

Example Code:

[code language=”scala”]
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

/**
Load test on scalaJobz Rest api for find all jobs
*/
class TestScript extends Simulation {
val baseurl = “http://www.scalajobz.com/findAllJobs"
val httpConf = http.baseURL(baseurl)

val scn = scenario(“Finding all jobs”)
.exec(
http(“Request”)
.get(baseurl)
.check(status.is(200)))

setUp(scn.inject(atOnceUsers(5))).protocols(httpConf)
}
[/code]

Running the Scenario

$ sbt test

Result

Screenshot from 2015-07-09 15:45:37

it provides meaningful reports through we can easily understand our result. Report is present in our target folder.

Screenshot from 2015-07-09 15:56:01

References:

--

--

Knoldus Inc.
Knoldus - Technical Insights

Group of smart Engineers with a Product mindset who partner with your business to drive competitive advantage | www.knoldus.com