First time guide to run JMeter tests on Docker

Swetha PN
6 min readMay 11, 2021

JMeter tests can be executed on GUI and non-GUI in a headless front, both of which are easy to set-up for JMeter enthusiasts.

However, there are instances where developers/remote stakeholders/shared testing teams have to execute the Performance tests on different machines.

Even when the testing team does not have any reservations around sharing the test scripts, the knowledge transfer on how to execute Jmeter scripts is an exhaustive process. There is so much to hand over from test data, folder structures, understanding active listeners, and finally the execution set up.

DOCKER SOLUTION

To make the hand-over simple one can execute JMeter test scripts via Dockers — to reduce the effort of setup significantly for all the parties involved.

Only four things are required to get things moving of which most of the steps are one time set up only

STEP 0: Pre-requisites

  • Docker Desktop software installation
  • Folder Structure Set up on Local drive

STEP 1: Pull the JMeter Docker Image

STEP 2: Keep the Jmeter Test scripts and data files ready

STEP 3: JMeter test run command to execute the load tests

PROS of the Approach

Pros vs Cons

Step by Step Guide

In a few easy steps, you can execute your first jmeter load test run using Dockers in the local machine.

Please note that this document will not discuss what is Docker and the inner workings of Docker in the interest of keeping the article short and crisp.

STEP 0 : Pre-requisites

— — — — — — — — — — — — -One Time SETUP — — — — — — — — — — — -

SYSTEM

Will be using a Windows Machine for the set up. Using Mac should also be pretty straightforward

I. SOFTWARES

1. Docker Desktop

Install Docker desktop on your windows machine

https://hub.docker.com/editions/community/docker-ce-desktop-windows

2. Windows PowerShell CLI

Or You can use any CLI to interact and run docker commands

II. FOLDER STRUCTURE

Create the below folders in the structure mentioned in the screen capture to store scripts and generated logs & html reports.

Main Root: C folder > Root folder: jmeter-base

Under the Root folder, Create three sub-folders as mentioned below:

>>>html (reports)

C:\jmeter-base\html

>>> logs

C:\jmeter-base\logs

>>>TestBlazedemo (Project folder to contain the scripts and data feeder files)

C:\jmeter-base\TestBlazedemo

Local Drive: C:\jmeter-base

Note: You can use any folder structure but for first timers it is recommended to follow this approach for ease of setup.

DOCKER ACTIVITY

— — PULL JMETER DOCKER IMAGE — — -

Step 1 : One time ONLY

Launch PowerShell CLI from Windows search bar. If the docker desktop is successfully installed, the command should display the version number

docker — version

docker — version (double hyphen)

Run the below command to install the docker image

docker pull swethapn14/repo_perf:JmeterLatest

Pull command for JMeter Docker image

Note: You should see a message that the Pull is successful. As I already have it, I see that the image is up to date

STEP 2: Keep the Test scripts handy

Place your JMeter/jmx test scripts in the local folder mentioned

C:\jmeter-base\TestBlazedemo

**For this article, I placed some sample test scripts in the below GitHub public Repository.

https://github.com/swethapn/blazeDemo

Blazedemo script: The jmx script searches for a flight and purchases a random airline ticket from departure city to a destination city.

C:\jmeter-base\TestBlazedemo

Project folder contains jmx, csv and pdf files

STEP 3: Run the FIRST JMETER TEST RUN on DOCKER

Launch PowerShell CLI > Run the below docker run command to execute the load test

Docker run

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

docker run -v C:/jmeter-base:/workspace swethapn14/repo_perf:JmeterLatest -Jthreads=10 -Jrampup=20 -n -t /workspace/TestBlazedemo/Blazedemo.jmx -l /workspace/logs/Blazedemo_10Vu.jtl -e -o /workspace/html/10VuReport

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Parameters to change in the run command for every test run

· Jthreads — Number of users for the load test

· Jrampup — The time for the users to initiate in seconds

· Change the test script as appropriate

· Log file’s name to change for every test run (**mandatory)

· Html report name to change for every test run(**mandatory)

TEST RESULTS

After the test finishes, the html report will be stored in the html report folder provided in the run command.

Double click on the index.html file
JMeter HTML Report

DOCKER RUN Command Explained

JMeter command to execute test runs via Docker -

docker run -v C:/jmeter-base:/workspace swethapn14/repo_perf:JmeterLatest -Jthreads=10 -Jrampup=20 -n -t /workspace/TestBlazedemo/Blazedemo.jmx -l /workspace/logs/Blazedemo_10Vu.jtl -e -o /workspace/html/10VuReport

The command does the work needed to execute a load test with ‘10’ users that will ramp up in ‘20’ seconds. The users inject traffic on the test script Blazedemo.jmx and write the results to a log file named TestBlazedemo_10Vu_5Loop.jtl. After the test finishes, the JMeter HTML report will be automatically generated & placed in the html/10VuReport folder in the workspace(C:/jmeter-base)

COMMAND to execute the test on your Company’s PROXY

— —

docker run -v C:/jmeter-base:/workspace swethapn14/repo_perf:JmeterLatest –H proxy.xxx.com –P XXXX -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 -Jthreads=10 -Jrampup=20 -n -t /workspace/TestBlazedemo/TestScriptName.jmx -l /workspace/logs/ProjectName_testEnv_Datetime_NoOfVu_Vu.jtl -e -o /workspace/html/TestReportName_NoOfVu_Project_Report

— —

Attributes :

-H proxy.xxx.com –P 3120 : The Host and Port on which the Proxy of your Organization is set up

-Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 : Transport Layer security to access the Application under test

Pointers on CSV Data Set Config — TestData

CSV Data Set configs are popularly used to feed test data to jmeter scripts. It is included in the Test Plan and contains mapping to the CSV file location.

Please note that there are a couple of pointers to note for executions on Docker vs executions in JMeter GUI.

Keep a look out on the forward and backward slashes (‘/’ ‘\’) in the file paths specified

Docker Executions : CSV file Path

The CSV file path path should be mapped to Docker volume : workspace

/workspace/ProjectName/Filename.csv

workspace

For JMeter GUI Test Runs

The CSV File Path should point to the root folder

C:\jmeter-base\ProjectName\Filename.csv

Root folder

Recap

The above steps allows developers/team members to do one of the following:-

Hope this helps.

--

--