Create Gatling Test Project

Learn to create a new project where we can write Gatling test scripts.

In the previous lesson, we learned how to set up the environment for writing our first Gatling test script. In this lesson, we will create a basic project structure and add the necessary dependencies.

Creating the basic project structure

Mac / Linux

$ mkdir -p gatling-load-test/src/{test,main}/{scala,resources} gatling-load-test/src/test/scala/simulations

Windows

$ mkdir gatling-load-test gatling-load-test\src gatling-load-test\src\main gatling-load-test\src\main\resources gatling-load-test\src\main\scala gatling-load-test\src\test gatling-load-test\src\test\scala gatling-load-test\src\test\resources gatling-load-test\src\test\scala\simulations

Initializing Gradle

Run the following command from the terminal:

$ cd gatling-load-test
$ gradle init

When we run the above commands, we will see the interactive message as shown below:

Starting a Gradle Daemon (subsequent builds will be faster)

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 1

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2] 1

Project name (default: gatling-load-test):


> Task :init
Get more help with your project: https://guides.gradle.org/creating-new-gradle-builds

BUILD SUCCESSFUL in 15s
2 actionable tasks: 2 executed

Note: We will select the default settings in this interactive message.

Once the above commands are run successfully, the folder structure should look like this:

Adding dependencies and Gatling task

Replace the content of build.gradle with the following:

plugins {
    id "scala"
    id "idea"
    id "eclipse"
    id "com.github.lkishalmi.gatling" version "3.3.4"
}
 
repositories {
    jcenter()
}
 
dependencies {
    compile "io.gatling.highcharts:gatling-charts-highcharts:3.3.1"
}

sourceSets {
    gatling {
        scala.srcDirs = ["src/test/scala"]
        resources.srcDirs = ["src/test/resources"]
    }
}

gatling {
    jvmArgs = [ '-server', '-Xms512M', '-Xmx2048MB' ]
    systemProperties = System.properties
    simulations = {
        include "**/simulations/**/*.scala"
    }
}

We are using a Gatling Gradle Plugin.

gatlingRun - the task that runs the Gatling simulation, which comes from the Gatling Gradle plugin.

The following is the plugin configuration:

gatling {
    jvmArgs = [ '-server', '-Xms512M', '-Xmx2048M' ]
    systemProperties = System.properties
    simulations = {
        include "**/simulations/**/*.scala"
    }
}  
  • jvmArgs – arguments that are passed to JVM.

    • -server – indicates to the launcher that this machine is a server-class machine.
    • -Xms512M – sets the minimum heap to 512 MB
    • -Xmx2048MB – sets the maximum heap to 2 GB
  • systemProperties – passes all the System.properties to Gradle launcher.

  • simulations – includes all simulation Scala files matching the pattern "**/simulations/**/*.scala". Similarly, we can add an exclude pattern to Scala files.

Get hands-on with 1400+ tech skills courses.