Trifork Blog

Axon Framework, DDD, Microservices

JMeter

April 24th, 2012 by
|

JMeter is a tool designed to load test functional behavior and measure performance. You can use JMeter to simulate a heavy load on an (web)applications.

In order to perform the tests you need test data. This test data can be different depending on the environment. It would be handy to load the data within the specific environment in order to use the data in the test suite. I make the data available via an HTTP call the url can be made specific for the different environments. The data will be presented as an XML to JMeter.

In this blogpost I am going to show you how to install and configure JMeter using the http call for test data.

Installation

If you have a JRE installed it is as simple as.

1. Download Jmeter
2. Unpack the archive
3. Launch jmeter.sh of jmeter.bat from the bin subdirectory

Load the test data

We add some variable to the Test Plan to have these available later.
Check ‘Run Thread Groups consecutively’ in the Test Plan to first run the thread group to load the data and then the thread group for the test suite.

${__P(users.count, 2)} means that the property users.count is read if it doesn’t exist 2 is used (default value).
The properties can be injected from the command (-J), in the property file (jmeter.properties) or if you use maven (with maven-jmeter-plugin):

<plugin>
  <groupId>org.apache.jmeter</groupId>
  <artifactId>maven-jmeter-plugin</artifactId>
  <version>1.0</version>
  <executions>
    <execution>
      <id>jmeter-tests</id>
      <phase>pre-site</phase>
      <goals>
        <goal>jmeter</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <reportDir>${project.build.directory}/jmeter-reports</reportDir>
    <jmeterUserProperties>
      <hostname>test-server</hostname>
      <port>8080</port>
      <target.datafile>${project.build.directory}/testdata</target.datafile>
      <users.count>20</users.count>
    </jmeterUserProperties>
  </configuration>
</plugin>

We first add a ‘Load Test Data’ Thread Group (you can also use a setUp Thread Group) with 1 thread.

This Thread Group will contain a transaction controller, this is a handy way to group all samplers into one single action (for example to gather statistics).


You can then use an HTTP Request sampler to load the data. In this sampler, you can use a Response Assertion to check the response code.


Then we need to save the output into a file, for this we use Save Response to a file.


Now we have test data available in a file that we can read to run tests.

Continue with the tests

We first add a ‘Tests’ Thread Group .


We want to run multiple tests but we don’t want to run them sequentially in the same order. We can use a Ramdom Controller.
If some samples are called multiple times, you can add a new disabled Thread and add your samples therein.
From the ‘Tests’ Thread Group, you can use a Module Controller and select the module from the drop down.


In your controller, you need first to load some parameters from the test data.
This can be done with User Parameters and use __XPath function.
You can also use ${_threadNum} to access specific data depending of the running thread.


Then you can do the test by reusing the parameters.

Conclusion

You can achieve performance testing by using test data available on the environment the tests should be run.

One Response

  1. April 10, 2013 at 09:03 by Dzmitry Kashlach

    Thank you for the guide! A couple of useful articles:
    analyzing test results
    creating database test-plan