Gatling Installation And Configuration (2024)

Gatling is an open-source load testing tool initially crafted for Scala when launched in 2015 but after version 3.7 it started supporting Java along with Scala. This article provides detailed information on Gatling installation and configuration for Java.

Prerequisites

Download and install the below-mentioned software and tools to start with the Gatling tool.

  • Java JDK(Version 11+)

Download JDK from the Oracle website and configure the Java_Home variable. After successful configuration check the java version.

  • An IDE (IntelliJ/VSCode)

Download and install an IDE of your choice.

  • Maven or Gradle

Installation Of Gatling

Gatling performance and load testing tools installation is a straightforward process in newer versions. Earlier we could install the Gatling tool using any of the approaches mentioned below.

1) Standalone mode(By Unzipping the files)
2) By Using Maven
3) By Using Gradle

Gatling -Java Installation

In this article, we are referring to Gatling version 3.11.2. Follow the below-mentioned steps for setting up the Gatling Java Maven project.

1) Navigate to the official gatling link.
2) Click on the download gatling button.
3) Click on Download Now.

A Zip file will be downloaded which we need to extract and save on our machine. Open up the extracted directory and navigate to the bin folder.

Gatling Installation

The Gatling bundle follow this structure as:

src/test/java: This folder contains the simulation code.

src/test/resources: This folder keeps non-source code files such as feeders, request body templates and configuration files for Gatling and log back.

pom.xml: This XML file contains information on the project and the required dependencies.

target: The Target folder store stores the generated test results.

mnvw: This file helps in opening Gatling in interactive mode for Mac/Linux users.

mnvw.cmd: This file is used by Windows users to launch the Gatling tool in the interactive mode.

Gatling Recorder for Windows: If we want to work with the Gatling recorder in Windows then we first need to set %GATLING_HOME%\bin in the path variable. Then execute the below-mentioned command.

mvnw.cmd gatling:recorder

This command will launch the command prompt and the Gatling recorder.

Gatling Recorder for macOS: For Mac OS executes the mnvw file from the terminal.

./mvnw gatling:recorder

Gatling Example Simulation In MAC/UNIX:

Gatling bundles with example simulation scripts by default. We can choose any of the simulations we want to execute out of these scripts.

1) Go to Terminal
2) Navigate to the location where the Gatling directory is saved.
3) Execute the test command.

(For Mac/Linux)

./mvnw gatling:test

(For Windows)

mvnw.cmd gatling:test


5) Choose a simulation number(0 for basic simulation)
6) Enter a run description(This description will be visible on the generated report, however, it is completely optional).

Gatling Java simulation

Once the simulation is done, Gatling will also print out a link to the full test report that is automatically created at the end of each test execution. A detailed report has been generated under the “targets” folder.

Please open the following file: /Users/user/Desktop/gatling-charts-highcharts-bundle-3.11.2/target/gatling/computerdatabasesimulation20200916072019032/index.html

Refer to the generated report in the below section.

Gatling HTML Report

A beautiful HTML report is generated which consists of several sections like available ranges, active users, requests hits per second etc. This report also depicts the execution stats, response time distribution etc in the details tab.

B) Gatling installation using Maven

To use the Gatling tool with Maven we need to install the Gatling Maven plugin. This plugin will enable us to run Gatling scripts from the command line. We can either clone the existing Gatling-Java-Maven repository to work or create a new Maven project. Let’s see both options.

1) Create a New maven project

1.1) Open IDE and create a new Maven project, Provide the name of your choice.

    1.2) Open pom.xml

    1.3) Add gatling-maven-plugin dependecy.

    1.4) Add gatling-charts-highcharts dependency

      <dependencies>
        <dependency>
          <groupId>io.gatling.highcharts</groupId>
          <artifactId>gatling-charts-highcharts</artifactId>
          <version>MANUALLY_REPLACE_WITH_LATEST_VERSION</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
      
      <plugin>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-maven-plugin</artifactId>
        <version>LATEST_VERSION</version>
      </plugin>

      2) Clone existing Gatling Java project

      • Go to this repo
      • Clone this repo
      • Open the demo project from the cloned repository in the IDE
      • Clean and build the project.

      To execute the tests run mvnw command.

      ./mvnw gatling:recorder

      Gatling installation using Gradle

      Gradle is a build management tool like Maven. To use Gradle for Gatling tool install Gradle with version 7+.

      In the Gradle project open the build.xml file and add the below-mentioned dependency.

      plugins {
        id "io.gatling.gradle" version "Your version"
      }

      To run all the simulations in the Gradle project on Mac/Linux use this command.

      ./gradlew gatlingRun

      To run all the simulations in the Gradle project on Windows use this command.

      gradlew.bat gatlingRun

      To run a single simulation specified by its name use the below command

      ./gradlew gatlingRun --simulation com.project.simu.MySimulation

      To run all simulations together we can execute the below command.

      ./gradlew gatlingRun --all

      To launch the Gatling recorder using the Gradle plugin use the below command.

      ./gradlew gatlingRecorder

      Conclusion

      Gatling’s unparalleled performance testing capabilities coupled with Java’s robustness make it a strong choice for performance testing. In this guide, I have curated all the steps required to start with Gatling installation and configuration with Java DSL.

      Discover more from AutomationQaHub

      Subscribe now to keep reading and get access to the full archive.

      Continue reading