Drive your Gatling with Maven Command Line Arguments

SunilSK
2 min readOct 10, 2020
Load tests triggered by Maven Commands

After building your Gatling scripts , you would like to parameterize the simulations using an external command line arguments (useful when you are running form your CI/CD tools ).

💡 You can refer if you need to see how the maven project is built

Assuming you have set up Gatling simulation and in my case the name of the simulation is “GtlMvnSimulation”.

Here’s the default maven command to run this simulation

mvn gatling:test -Dgatling.simulationClass=CodeReuseWithObjects

Command Line Parameters for Gatling Scenarios

The first thing we do is define a method/function to extract the properties. This method will look for the environment variables of the specified name. We need to make these command line params as optional as we need to be able to run our simulation in default mode.

  1. This function getProperty checks for the variable . (2) System.getenv(propertyName) reads the variable . (3.) If its not provided then gets it from the default value.
private def getProperty(propertyName: String, defaultValue: String) = {Option(System.getenv(propertyName)).orElse(Option(System.getProperty(propertyName))).getOrElse(defaultValue)}

4. In this we are having it get the userCount, rampDuration,testDuration from the commandline . If they are not provided then it defaults them to 2 ,5 and 60 respectively. Similarly you can pass any other set of variables that are needed to drive your environment variables.

Let’s run a test from the command line to test this out. Open a terminal or prompt and type the following :

mvn gatling:test -Dgatling.simulationClass=simulations.RuntimeParameters -DUSERS=10 -DRAMP_DURATION=5 -DDURATION=30

👏 We are passing in the USERS, RAMP_DURATION and DURATION of the Gatling test at runtime through these parameters.

--

--

SunilSK

Entering into Full Stack development from the analytical world of Performance Engineering !