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:
- HTTP Request which define the path and parameters of a VERB request. (REST verbs are GET, POST, PUT, DELETE)
- HTTP Request Defaults that enables all requests to share mainly web server name and port.
- 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).
- Response Assertion enable asserts based on pattern strings matching various fields of the response.
- It uses ORO Perl5 regular expressions.
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
- 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
- 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:
#jmeter.save.saveservice.output_format=csv
like this:
jmeter.save.saveservice.output_format=xml
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)
summariser.name=summary
#
# interval between summaries (in seconds) default 30 seconds
#summariser.interval=30
#
# Write messages to log file
summariser.log=true
#
# Write messages to System.out
summariser.out=true
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: http://jmeter.512774.n5.nabble.com/Removing-variables-td534792.html
Or this solution based on the documentation: beanshell
vars.initialize();
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:
- [Learn JMeter in 60 minutes](https://www.youtube.com/watch?v=cv7KqxaLZd8
- JMeter Assertions
- Performance testing JMeter
- Performance tuning: Pulling a rabbit from a hat
- X-Path validator