Why Plugins

Plugins are used in a software for adding new functionalities inside the program definition. Plugins are helpful for adding extra functionalities inside the software without making it a heavier one.

There are different types of plugins available for Gatling. Some are official and some are third party plugins. So, without wasting more time, let us move to Plug-ins of Gatling.

Official Plugins of Gatling

The official plugins of Gatling are as follows:

  • SBT plugin: The SBT plugin integrates Gatling with SBT and allows us to use Gatling as a testing framework also.
  • Maven Plugin: This plugin helps us to launch Gatling while building our projects.
  • Maven Archetype: It helps us bootstrap a maven project with Gatling dependencies and plugin.
  • Jenkins Plugin: In Jenkins, we are able to track Gatling's simulation launched by Maven Plugin.
  • Bamboo Plugin: This Plugin can launch Gatling FrontLine and display live simulations and metrics.
  • TeamCity Plugin: This Plugin can also launch Gatling FrontLine and display live simulations and metrics.

SBT Plugin for Gatling

The SBT Plugin integrates Gatling with SBT and allows us to use Gatling as a testing framework also. There are several steps involved in configuring the SBT to integrate with the Gatling.

While Setting up, we need to add the following code into the folder Project/plugins.sbt.


									 addSbtPlugin("io.gatling" % "gatling-sbt" % "2.2.2")
									 


This is to keep in mind that, the following dependencies must be added before proceeding further.


									"io.gatling.highcharts" % "gatling-charts-highcharts" % "2.3.0" % "test"
									"io.gatling"% "gatling-test-framework"    % "2.3.0" % "test"
									


After that in the .scala bulid, the following code has to be added.



import io.gatling.sbt.GatlingPlugin
lazy val project = Project(...)
					.enablePlugins(GatlingPlugin)
					.settings(libraryDependencies ++= /* Gatling dependencies */)


For the SBT 0.13.6 or the later versions in your .SBT file, add the code below.


									enablePlugins(GatlingPlugin)
									libraryDependencies ++= /* Gatling dependencies */
									


With SBT testing framework, we are able to run Gatling simulations using SBT standard test, testOnly, testQuick and many other tasks.

The SBT Plugin introduces many customizations and it should be kept in mind that it is not interfering with any unit tests, so the commands are integrated to custom configurations, requiring us to prefix them with gatling or gatling-it, eg. gatling:test or gatling-it:test.

Test and Integration Tests configurations or mode

The SBT plugin provides two different SBT configurations, they are Gatling and GatlingIt. They are assigned to different source directories so that it becomes possible to separate our simulations according to our needs.

Basically two things must be taken care of:

  • Our simulations with low injection profiles, which serves as functional tests, should reside inside the folder path‘src/test’ which is the default source directory for the Gatling's configuration, and should run along our unit tests, as soon they complete.
  • The bigger and more complex simulations with high injection profiles, should reside in ‘src/it’ which is the default source directory for the GatlingIt configuration and should be able to run in need only.
Let us now see the default settings. For the Gatling Configuration:
  • By default, Gatling simulations must be in src/test/scala, configurable using the Source in Gatling Settings.
  • By default, Gatling reports are written to target/gatling, configurable using the target in Gatling Setting.
For the GatlingIT Settings.
  • By default, Gatling simulations must be in src/it/scala, configurable using the scalaSource in GatlingIt Setting.
  • By default, Gatling reports are written to target/gatling-it, configurable using the target in GatlingIt Settings.
If any case the default settings are overridden somehow, we need to reset those settings on the project, in the way:

									scalaSource in Gatling := sourceDirectory.value / "gatling" / "scala" 
									lazy val root = (project in file(".")).settings(inConfig(Gatling)(Defaults.testSettings): _*)
									


Below we will see the additional tasks which are performed by the Plugin:

  • gatling(-it):startRecorder: It starts the Recorder, configured for saving our recorded simulations.
  • gatling(-it):generateReport: It generates reports for a specified report location.
  • gatling(-it):copyConfigFiles: It copies the Gatling’s configuration files.

Maven Plugin for Gatling

This Plugin can be launched while building our projects. To set up the Gatling-Maven, the following dependencies should be added.


									
<dependencies>
  <dependency>
    <groupId>io.gatling.highcharts</groupId>
    <artifactId>gatling-charts-highcharts</artifactId>
    <version>X.Y.Z</version>
    <scope>test</scope>
  </dependency>
</dependencies>

<plugin>
  <groupId>io.gatling</groupId>
  <artifactId>gatling-maven-plugin</artifactId>
  <version>X.Y.Z</version>
</plugin>
									
									
									


This below configuration can be used, but this is optional.


<configuration>
  <configFolder>${project.basedir}/src/test/resources</configFolder>
  <dataFolder>${project.basedir}/src/test/resources/data</dataFolder>
  <resultsFolder>${project.basedir}/target/gatling/results</resultsFolder>
  <bodiesFolder>${project.basedir}/src/test/resources/bodies</bodiesFolder>
  <simulationsFolder>${project.basedir}/src/test/scala</simulationsFolder>
  <runDescription>This-is-the-run-description</runDescription>
<!--    <noReports>false</noReports> -->
<!--   <reportsOnly>directoryName</reportsOnly> -->
<!--   <simulationClass>foo.Bar</simulationClass> -->
<!--   <jvmArgs> -->
<!--     <jvmArg>-DmyExtraParam=foo</jvmArg> -->
<!--   </jvmArgs> -->
<!--    <fork>true</fork> -->
<!--    <propagateSystemProperties>true</propagateSystemProperties> -->
<!--   <failOnError>true</failOnError> -->
</configuration>									

Running the Plugin

The Gatling Maven Plugin can be directly launched with the test or the integration-test task.


									mvn gatling:test    
									mvn gatling:integration-test 
                                    
								
									


The next task is to configure the execution block. This below code can be used to configure the execution block.


									<plugin>
  <groupId>io.gatling</groupId>
  <artifactId>gatling-maven-plugin</artifactId>
  <version>${gatling.version}</version>
  <!--This is optional, if you are having only one simulation-->
  <configuration>
    <simulationClass>Foo</simulationClass>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
      </goals>
    </execution>
  </executions>
</plugin>
									


After the configuration of the execution block, we may choose to run the plugin several times in a build, in order to to run several simulations simultaneously. The other way is to configure several execution block each with having a different configuration block.

It has to be kept in mind, that those won't be kept while running gatling:test, as the execution would be initiated by Maven's Cycle.


<plugin>
  <groupId>io.gatling</groupId>
  <artifactId>gatling-maven-plugin</artifactId>
  <version>${gatling.version}</version>
  <executions>
    <execution>
      <id>execution1</id>
      <goals>
        <goal>integration-test</goal>
      </goals>
      <configuration>
        <simulationClass>Foo</simulationClass>
      </configuration>
    </execution>
    <execution>
      <id>execution2</id>
      <goals>
        <goal>integration-test</goal>
      </goals>
      <configuration>
        <simulationClass>Bar</simulationClass>
      </configuration>
    </execution>
  </executions>
</plugin>

Conclusion

In this article, we have seen the overview of the SBT and the Maven Plugin.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions