How to run a JMeter test from the command line
To run a JMeter test from the command line, we need to follow the steps below:
- Open a terminal or command prompt.
- Navigate to the directory where the JMeter executable file is located.
- In our case, the file is inside the JMeter’s bin directory
/opt/jmeter/bin. If we have added the directory that contains thejmetercommand to our system’sPATHenvironment variable, we can run thejmetercommand from any directory.Note: To find the full path of our saved file in the current directory and its subdirectories, we can use the
findcommand in the following manner:find . -name "test.jmx"wheretest.jmxis the name of our executable file.
- In our case, the file is inside the JMeter’s bin directory
- Enter the following command to run the test:
jmeter -n -t /path/to/your/test.jmx -l /path/to/save/results.csv
Let’s take a look at how we can do this.
Run the test.jmx file
To add the directory (/opt/jmeter/bin) to the PATH environment variable permanently (not just for the current session) from the terminal, enter the following command:
echo 'export PATH="$PATH:/opt/jmeter/bin"' >> ~/.bashrcsource ~/.bashrc
Line 1: The
echocommand appends theexport PATH="PATH:/opt/jmeter/bin"' >> ~/.bashrcline to the end of the in the user’s home directory (.bashrc file [object Object] ~refers to the user’s home directory). This sets thePATHvariable for the current user and allows thejmetercommand to be executed from anywhere in the terminal.Line 2: The
source ~/.bashrcreloads the.bashrcfile in the current shell session so that the updatedPATHvariable is available for the current session.
To gain hands-on experience, please run the above commands in the following terminal to add the bin directory to the PATH environment variable.
If we want to run the test.jmx file and place the test results in the result.csv file that we have already created in the JMeter’s bin folder, we enter the following commands:
# command to run the JMeter testjmeter -n -t ./opt/jmeter/bin/test.jmx -l result.csv# command to display the contents of the CSV file (result.csv) in a human-readable formatcsvtool readable result.csv
In the code above:
-nspecifies JMeter to run the test in a non-GUI (CLI) mode-tspecifies the path to the JMeter test file (.jmx)-lspecifies the path to save the test results filecsvtooldisplays the.csvfile in the terminal in a human-readable format with headers for each column
We have included the commands above in the terminal below. Click the terminal to see the tests being executed.
Free Resources