Jmeter + Maven Integration – Some facts

JMeter is the most widely used open source tool for analysing the performance of different applications. Here I will be discussing not only how we can “integrate” JMeter with Maven but also discuss what common “hurdles” we usually encounters with the integration.

Maven basics are required to be known, to understand following discussion.

So lets kick off this interesting discussion in the form of incremental steps.

Step 1 — Create a Maven Project.

Lets start with creating an empty maven project using  maven ‘archetype‘ plugin with the goal ‘generate‘ ie. mvn archetype:generate.

Now maven project is in place with a default POM file generated in root folder.

Step 2 — Create a Jmeter Test Plan(Jmeter GUI).

Create a Jmeter test plan to have performance benchmarking of your application.

And place it in your maven directory — src/test/jmeter/{YourTestPlan}.jmx

Step 3 — Use ‘jmeter-maven-plugin’.

Maven plugin ‘jmeter-maven-plugin’ has the capability to interact with Jmeter plan files or project(.jmx). Add this plugin to the POM file.


"<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>1.10.1</version>"

//And just attach the goal "jmeter" to a phase "verify" as

"<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>"

Step 4 — Avoid “Out Of Memory” errors during load test.

When we executes the load test with large number of concurrent users, then usually JVM goes Out Of Memory due to less Java heap space. So to avoid it, we need to increase the java heap space. We can pass xms and xmx to 1024 with ‘jMeterProcessJVMSettings’ parameter.


"<jMeterProcessJVMSettings>
<xms>1024</xms>
<xmx>1024</xmx>
<arguments>
<argument>-Xprof</argument>
<argument>-Xfuture</argument>
</arguments>
</jMeterProcessJVMSettings>"

Step 5 — Pass parameters to Jmeter Test Plan through maven.

We can not live with all the parameters in load tests to be hard coded or static in test
plan, we need to have a mechanism where tests would execute for different sets of inputs.
So same we want when executing through maven.

Inside a configuration tag of ‘jmeter-maven-plugin’, use ‘propertiesUser‘ tag
where parameters can be defined which will flow inside your JMeter tests.

"<propertiesUser>
<threadcount>${concurrency}</threadcount>
<loop>${loopCount}</loop>
</propertiesUser>"

Now look carefully how inputs will be communicated to JMeter, in JMeter test script,
‘threads’ in ThreadGroup are mentioned as ${__P(threadcount,)} which means threads are
not static but based on user input. To pass ‘threadcount’
from maven to test script we added <threadcount>${concurrency}</threadcount>.

That means when test is triggered through maven, then “threadcount” is passed and will be used in your Jmeter script.

And, ${concurrency} means that user will give concurrency parameter while executing maven command as “-Dconcurrency=500”.

Step 6 — What Tests to execute.

As per Step 2, we have placed our test plans in directory (src/test/jmeter).
This is the default directory which ‘jmeter-maven-plugin’ looks for.
Otherwise we can instruct the plugin to look for tests in our custom directory through ‘testFilesDirectory’ tag.

eg. <testFilesDirectory>${project.base.directory}/src/test/mydirectory/</testFilesDirectory>

By default ‘jmeter-maven-plugin’ executes all tests present in testFilesDirectory.
But, we can also configure to specify the test as well, by

Specifying <testFilesIncluded> as

  “<testFilesIncluded>

     <jMeterTestFile>test1.jmx</jMeterTestFile>

     <jMeterTestFile>test2.jmx</jMeterTestFile>

    <testFilesIncluded>”

Specifying <testFilesIncluded> Using Regex as

   “<testFilesIncluded>

       <jMeterTestFile>foo*.jmx</jMeterTestFile>

    </testFilesIncluded>”

Specifying <testFilesExcluded> as

   “<testFilesExcluded>

      <excludeJMeterTestFile>test3.jmx</excludeJMeterTestFile>

      <excludeJMeterTestFile>test4.jmx</excludeJMeterTestFile>

    </testFilesExcluded>”

Specifying <testFilesExcluded> Using Regex as

“<testFilesExcluded>

<excludeJMeterTestFile>*bar.jmx</excludeJMeterTestFile>

</testFilesExcluded>”

To even make this parameterized, use <testFilesIncluded> as follows –

<testFilesIncluded> ${TestNameToExecute}.jmx </testFilesIncluded>

And in maven command user can give the test name to execute as –“DTestNameToExecute=test1”

I suppose till this point everybody is with me. Don’t worry if there is any confusion in above steps,
as this will be clear when I integrate all the components we discussed.

Now, lets integrate what we discussed.

‘jmeter-maven-plugin’ looks like as follows in POM (go through each line carefully) —

Lets say in /src/test/jmeter I have 3 Tests (Test1.jmx,Test2.jmx,Test3.jmx).

To execute Test 1 —

“mvn verify -Dconcurrency=500 -Drampup=2 -Dloop=10 -Dapplication.base.url=www.linkedin.com -DTestName=Test1”

Isn’t it really cool!

Hope this is worth sharing 🙂

Comments