---
title: "Load Testing using Gatling and JUnit in Scala"
canonical: "https://docs.getxray.app/space/XRAYCLOUD/74355371/Load%20Testing%20using%20Gatling%20and%20JUnit%20in%20Scala"
format: markdown
---
# Overview

Gatling is tool for load/stress testing that can be used to create stress tests in websites. 

In this tutorial, we will create a [Gatling](http://gatling.io/) simulation containing some basic HTTP interaction and we evaluate the obtained results in terms of performance and failure requests, using Gatling's assertions.

**Gatling v2.2 release** added support for JUnit reports, which can be processed by Xray.

# Description

Below is the simulation class containing 3 assertions. This code was directly run inside Gatling's folder after extracting the [v2.2.3 release Gatling bundle](https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/2.2.3/gatling-charts-highcharts-bundle-2.2.3-bundle.zip). 

##### **user-files/simulations/http/GoogleSimulation1.scala**

```scala
package xpandaddons.xray.gatling.simulations

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.http.request.builder.HttpRequestBuilder.toActionBuilder

class GoogleSimulation1 extends Simulation {
    val theHttpProtocolBuilder = http
        .baseURL("http://www.google.com")

    val theScenarioBuilder = scenario("GoogleTest")
        .exec(
            http("Search Request")
                .get("/search?q=x")

                /*
                 * Check the response of this request. It should be a HTTP status 200.
                 * Since the expected result is 200, the request will be verified as being OK
                 * and the simulation will thus succeed.
                 */

                .check(
                    status.is(200)
                )
        )

    setUp(
        theScenarioBuilder.inject(atOnceUsers(10))
    )

        /*
         * This asserts that, for all the requests in all the scenarios in the simulation
         * the maximum response time should be less than 50 ms.
         * If this is not the case when the simulation runs, the simulation will considered to have failed.
         */

        .assertions(
            global.responseTime.max.lt(50),
            forAll.failedRequests.count.lt(5),
            details("Search Request").successfulRequests.percent.gt(90)
        )
        .protocols(theHttpProtocolBuilder)
}
```


After successfully running the Test Case and generating the JUnit XML report, it can be imported to Xray (by using the either the REST API or the **Import Execution Results** action within the Test Execution).


```
bin/gatling.sh --simulation xpandaddons.xray.gatling.simulations.GoogleSimulation1
```



![image](media://d86c42bb-51ce-47f5-86cf-c1c7872d1de2)


Every Gatling's assertion is mapped to a Generic Test in Jira, as is the initial check for the HTTP status code. The **Generic Test Definition** field contains the full name of the class.

The Execution Details of the Generic Test contains information about the Test Suite, which in this case corresponds to the full name of the simulation class. 

When an assertion fails, then the actual value is displayed in the execution details.


![image](media://0575e49a-5fae-4b3f-98ea-5b209e8e4eb7)


As a side note, Gatling also generates an HTML report that provides many interesting and useful information in the context of load testing, including some interactive charts.


![image](media://3b2cb2ff-5592-4f07-ae04-9640c4ac4fa7)

# References

- [Assertions](https://docs.gatling.io/reference/script/core/assertions/)
- [Introduction to load testing with gatling](https://www.ivankrizsan.se/2016/05/06/introduction-to-load-testing-with-gatling-part-4/)