Quick Start your Gatling Journey with Maven

SunilSK
5 min readOct 9, 2020
GATLING — MAVEN

🛑 If you know Gatling and know the hows of Maven then you can quickly clone this official gatling-mvn demo repo : https://github.com/gatling/gatling-maven-plugin-demo and quickly kick start your journey.

What’s Maven archetype

In short, Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made. The name fits as we are trying to provide a system that provides a consistent means of generating Maven project.

Dividing it into 5 steps

  • Installing Maven
  • Setting up project using the mvn archtype.
  • Opening and setting up the Project in Intellij
  • Running your first Test.
  • Using Command Line Params to run your test.
  • Migrating to Gatling 3.4 (or any higher version)

Installing Maven

On Mac , If you do not have Homebrew (mac os’s package manager), then go ahead and install it:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To install Maven with Homebrew, open terminal window on your Mac OS and type the following command:

brew install maven

Check the version:

$ mvn -version

Setting up project using the mvn archtype.

  1. Open a terminal or command prompt and type:

mvn archetype:generate

2. Eventually you will see this prompt

3. Go ahead and type ‘gatling’

4.Simple type 1 to choose the Gatling archetype. On the next screen, choose the latest version. At the time we do not have 3.4 listed here but towards the end of the tutorial you have instructions to upgrade your project.

I typed in 35 to choose version 3.3.1 for this tutorial.

5. Enter the following details as per your project .

For the groupId type in com.wday.perf

For the artifactId type in sampleTest

For the version, simple press enter to accept 1.0-SNAPSHOT

Finally for the package, press enter again to accept com.gatlingTest as the package name.

Finally for the package, press enter again to accept com.gatlingTest as the package name.

Last of all type in Y to confirm all settings, and Maven will create a new project for you.

Opening the Project in Intellij

The next thing to do is import this project into your IDE. Here, I will import into IntelliJ. From the IntelliJ welcome page, select Import Project.

(OR From FILE> OPEN >) Browse to the project folder that you just created, and select the pom.xml file.

Click open, and Intellij will begin importing the project into the IDE for you.

IMP : Once the project is imported, open up the Project Directory pane on the left and expand the src > test > scala folder.

At this point, you might also need to mark the scala folder as source in IntelliJ. To do that, right-click on the scala folder and click Mark ‘scala’ Directory As -> Test Sources Root:

Double click on the Engine.scala class.

You might see a message No Scala SDK in module at the top of the screen. If so, click on Setup Scala SDK:

Check which versions of Scala you have available:

If you don’t have any version listed here, click on Create, choose a 2.12 version and click download. Alternatively, if you are having trouble downloading the Scala binaries through IntelliJ, you can instead download the Scala binaries directly from Scala-lang. Click on Download the Scala binaries as in this screenshot:

NOTE: It’s HIGHLY recommend using version 2.12 of Scala with IntelliJ — 2.13 doesn’t seem to play nicely with Gatling

Running your first Test.

Finally, right-click on the Engine object and select Run:

You should see a message like There is no simulation script. Please check that your scripts are in user-files/simulations. This is fine, as we do not have any simulations(test scripts) yet.

If you have reached till here then Congratulations 👏. Your gatling-mvn project is all set.

I’ll cover creating a simple Gatling Simulation in my next article and link it here.

Migrating to Gatling 3.4

The mvn archetype did show the latest version so here’s the quick way to upgrade the project.

  1. Updated the gatling version in the properties to 3.4 in pom.xml of your project. Intellij will prompt for importing. Go ahead and this might take few minutes.

2. Since we are manually making changes here (RISKY but quick ) so copy the 3 classes (engine,recorder and IDEPathHelper.scala) under the scala folder from plugins official repo

--

--

SunilSK

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