Smoke Testing With Gatling and Gradle

These days I had the opportunity to write some Gatling tests - an open-source load testing framework based on Scala, Akka and Netty.

We started with a very basic smoke test for Planets: A single user checking the server version URL.

The tests are written in Scala:

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

class SmokeTest extends Simulation {

  val baseUrl = "https://planets.datenkollektiv.de"

  val httpProtocol = http.baseURL(baseUrl)

  val pingScenario = scenario("PingPlanetsServer")
    .exec(http("request_planets_server_version")
    .get("/planets/server/version")
  )

  setUp(pingScenario.inject(atOnceUsers(1))).protocols(httpProtocol)
}

and integrated into our Gradle build:

apply plugin: 'scala'

The Gatling dependencies:

dependencies {
  compile group: 'io.gatling', name: 'gatling-app', version: gatlingVersion
  compile group: 'io.gatling', name: 'gatling-recorder', version: gatlingVersion
  compile group: 'io.gatling.highcharts', name: 'gatling-charts-highcharts', version: gatlingVersion
}

And a simple JavaExec task:

task gatling(type: JavaExec, dependsOn: 'compileTestScala') {

  classpath = sourceSets.test.output + sourceSets.test.runtimeClasspath

  main = 'io.gatling.app.Gatling'
  args '-sf', sourceSets.test.output,
    '-bf', sourceSets.test.output.classesDir,
    '-s', 'SmokeTest',
    '-rf', "${project.buildDir}" + '/reports/gatling'
}

That's all you need to run this simple smoke test:

$ ./gradlew gatling