As part of this article let’s try to understand how can we run Gatling scenarios as executable Java jar package instead of using Gradle, Maven or any other build tools. But before start on it, let’s try to understand what is Gatling and where can we use it?

What is Gatling

In single sentence, Gatling is a OpenSource load testing tool. Using Gatling, we can write Load test as code using Java/Scala programming language. As the tests are written as code, we can easily automate the tests invocation using CI/CD tools or we can even run on any instance having JVM.

How can I run Gatling scenarios

If you are using Gradle or Maven as build tools, gatling scenarios can be easily run using gatlingRun task. It’s works fine when we are running on CI/CD tools but when we want to run on some instance where build tools aren’t present, it creates issue. Also, when we use build tools, build tools itself takes some time and resources to run. To avoid the above mentioned issues, we can build an executable java jar file and use the same on any instance where JRE (Java Runtime Environment) is present.

How can I build executable jar

To be able run Gatling scenarios, we need to build fat jar or uber jar. Let’s see how can we create a uber jar

https://github.com/sumanmaity112/gatling-example/blob/main/src/gatling/java/com/suman/example/gatling/Application.java
https://github.com/sumanmaity112/gatling-example/blob/940f9c3f1be804e708f627368028db0f3a3dab62/build.gradle#L22-L50

As you can see we have gradle task named fatjar, which copies all the dependencies along with compiled codebase to jar file.

How can I use newly created uberjar

Once uber jar is created, we can easily run the jar on any instance having JRE installed. We can make use of following command

java -jar build/libs/gatling-example-1.0-SNAPSHOT-all.jar

By default, this newly created jar runs all the Gatling simulations, but incase we want run specific simulation(s), that’s also can be done using

java -jar build/libs/gatling-example-1.0-SNAPSHOT-all.jar <simulation name(s)>

What are the benefits of executable Jar

Executable jar has the following benefits

  • It can be executed on any system/containers with Java Runtime Environment
  • Uses lesser resources than build tools
  • Startup time is relatively lesser than when build tool is used to start the simulations

As you can see, Gatling as executable jar has many advantages over executing it using build tools. So, feel free to use this concept next time you are writing load test for your project.

PS: I hope you’ve enjoyed it, and if you’ve found it useful, please feel free to share with others or leave a comment 😃. Incase you want check the entire project, you can check it here.

Originally posted on medium.com.