Luis Custodio bio photo

Luis Custodio

XP | Software Craftsperson

Email Twitter LinkedIn Github Stackoverflow

JMeter is able to test many flavours of requests. Here the scope is just for HTTP requests, plus the tool itself and how it can manage to test multitenancy.

Apache JMeter is an Apache project that can be used as a load testing tool for analyzing and measuring the performance of a variety of services, with a focus on web applications.[1]

JMeter can be used as a unit test tool for HTTP, TCP connections and OS Native processes.

The basics can be found in this video, it goes through the main concepts:

  1. HTTP Request which define the path and parameters of a VERB request. (REST verbs are GET, POST, PUT, DELETE)
  2. HTTP Request Defaults that enables all requests to share mainly web server name and port.
  3. View Result Tree to check the request history. Requests and responses.
    • View Results Tree MUST NOT BE USED during load test as it consumes a lot of resources (memory and CPU).
  4. Response Assertion enable asserts based on pattern strings matching various fields of the response.

It’s commom to see an _ as part of the query string. This is part of the jQuery strategy to avoid caching. StackOverflow

Jenkins Integration

Integration with continuous integration server is easier than expected. Making sure that JMeter is capable of running on the build server (java on the path), the required steps are the following:

Generating the .jtl file

  1. Run JMeter on command line to generate the output C:\tools\jmeter\bin\jmeter -n -t .\%CODE_BRANCH%\Source\MultitenancyTests\MultitenancyTests.jmx -l .\%CODE_BRANCH%\Source\MultitenancyTests\MultitenancyTests.jtl
  2. With the Performance Plugin, consume the output generated.

The output need to be in xml format

Performance plugin doesn’t expect jlt in csv format (Which is the default output of latest version of JMeter). It require a manual change in one configuration file. Here is the reference, the main change is the output format, just remove the comment from the following line and change csv by xml:

like this:

Powershell vs batch

Jmeter need to run as batch, the powershelll is not working properly. It’s useful to changed as well the configuration to log the event when in CLI.

Enable logs in order to make the steps more descriptive

# Summariser - Generate Summary Results - configuration (mainly applies to non-GUI mode)
# Define the following property to automatically start a summariser with that name
# (applies to non-GUI mode only)
# interval between summaries (in seconds) default 30 seconds
# Write messages to log file
# Write messages to System.out

Always clean the output file

The jtl file summary is used to decide if the build was a success or a failure. If the jtl file stays on the build server, the average is always greater than 0% if once something went wrong. So it’s important to flush the file.

echo "****************** ~ JMETER ~ ******************"
echo Command location: %cd%
echo Configuration file location: ".\%CODE_BRANCH%\Source\MultitenancyTests\MultitenancyTests.jmx"

echo Clear out old results...
del .\%CODE_BRANCH%\Source\MultitenancyTests\MultitenancyTests.jtl

echo Running...
C:\tools\jmeter\bin\jmeter -n -t .\%CODE_BRANCH%\Source\MultitenancyTests\MultitenancyTests.jmx -l .\%CODE_BRANCH%\Source\MultitenancyTests\MultitenancyTests.jtl

echo "****************** ~ JMETER ~ ******************"


Reset Variable values.

Every time the thread is reused for another request, the local variables are kept and it can generate conflicts. To avoid this is always good to clean up the vars after the steps are finished.

This can be done like this:

Or this solution based on the documentation: beanshell


Passing variable

Sometime one would like to pass a variable in command line so that it could be used by jmeter test. In order to do this, in jmeter one should first define this variable as ${__P(TestCaseNumber)}. This in order to pass this variable in command line, one should do following

jmeter -n -t APITestScript.jmx -JTestCaseNumber=1234

Miscellaneous data: