Gatling is a highly capable load/performance testing tool. It hits your API with defined HTTP protocols and generates a beautiful report showing all scenarios with success and failure rate. It is designed for ease of use, maintainability and high performance.

In this blog, I’ll take you through the main components of Gatling Simulation Script. For the basic setup overview of Gatling, you can visit Gatling-Maven-Setup.

In Gatling Simulation Script, the most important component is a setUp() method. It executes the suite of test cases with specified ramped-up users at time boundaries/thresholds. The setUp() needs an HTTP configuration parameter to execute or hit the requested endpoint with given headers like content-type, access-tokens etc.

Given below is an example setUp():

  setUp(scenario.inject(constantUsersPerSec(perMinute(USERS_PER_MINUTE)) during(DURING_TIME minutes)))

Like you see in the above-given code, the setUp takes a Scenario to execute with some httpConf (i.e HTTP configuration).

With that said, the next component comes into the picture is a Scenario. It is kind of test cases which takes a single Endpoint to hit an up and running API provide its host URL.

   val validUser = repeat(10) {
      exec(http("Get Valid User")
    val inValidUser = repeat(10) {
      exec(http("Get InValid User")

A Scenario can also consist of multiple endpoints sequencing them in a chain of execs’ i.e. executions but it is only recommended whenever we have a process dependent scenarios i.e if an endpoint takes the output of another endpoint as input the former can be sequenced after the later in the same Scenario.

  val scn: ScenarioBuilder = scenario("My Service").repeat(5) {
    feed(feeder).exec {
      exec(http("Request 1")
        http("Request 2")

The next Component is httpConf:, it is the holder for the header configurations which will propagate with the request hit.

  val httpConf :HttpProtocolBuilder= http.baseURL(ConfigFactory.load("").getString("BASE_URL"))
    .acceptHeader("application/json; charset=utf-8")
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")

Then there is a Feeder we need many times.

val requestFeeder: RecordSeqFeederBuilder[String] = csv(FEEDER_PATH).circular

Yeah, so these were some important components of a Gatling Simulation Script we should be aware of. For a running example, please visit Gatling-Sample-Service.

Hope it could help.

Pasted image at 2017_11_27 04_17 PM

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s