How to create a JMeter test

What is JMeter?

JMeter is an open-source Java application used to perform load testing of the functional behavior of websites, web applications, servers, and networks. Load testing is a type of software testing where the performance of an application is measured while it’s being used by multiple users simultaneously. This is done to determine whether there are any bottlenecks in the application infrastructure when handling peak user load.

Setting up JMeter

  1. Install the latest version of the Java JDK from Oracle’s website. Download it from their site and install by following the OS-specific instructions. 

  2. After downloading and installing the Java JDK on our computer, we want to set the JAVA_HOME environment variable. This is an OS environment variable that we create to store the path to the folder where the Java JDK is installed.

    1. For Windows: Click the “Windows Start” button > “Settings” > “About” > “Advanced System Settings.” This opens the System Properties window. On the “Advanced” tab, click “Environment Variables.” To add the JAVA_HOME variable, click “New” and enter JAVA_HOME for “Variable Name.” Then, enter the full path of the folder where the Java JDK is installed for “Variable Value.”

    2. For Mac: Open the terminal and type the following command, echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.zshrc. This will create the variable and write it to the ~/.zshrc file, which is used to store environment variables.

  3. Go to the Apache JMeter site to download the latest version of JMeter. In most cases, we download the .zip file under “Binaries” on the “Download Apache JMeter” page.

Note: On a macOS, we need to allow installs from Apache by going to “System Settings” > “Privacy & Security,” and under “Allow application downloads from,” check the box “App Store and identified developers.”

  1. Extract the downloaded .zip file for JMeter and install the application following the OS instructions.

Download Apache JMeter page
Download Apache JMeter page

The “Download Apache JMeter” page can be reached by clicking on “Download Releases” from the left menu of the homepage.

The JMeter GUI

To open the JMeter GUI, we navigate to the application folder and run the /bin/jmeter.bat file on Windows OS or /bin/jmeter.exe on macOS or Linux OS. This opens the Test Plan IDE where we can build, debug, and run test plans. 

Opening jmeter.exe in macOS
Opening jmeter.exe in macOS

Components of the JMeter GUI

  • Main panel: This is where we edit different test components.

  • Left panel: This is where we organize our test plans and add components.

  • Icons: These are shortcuts to commonly used functions, and can also be accessed from the top menu.

The JMeter GUI
The JMeter GUI

Creating a JMeter test

In this section, we’ll create a simple test that simulates two users on a test e-commerce site and confirms that the requests were successful. 

For a basic test, we need three elements: a test plan, a thread group, and one or more samplers. A test plan is where the overall settings for a test are set, while a thread group is used to control the number of users simulated. Samplers perform the tests in JMeter, and sampler results can be viewed in listeners. In this example, we will add an assertion, which allows us to test that we received a particular response. We will also add a View Results Tree (a type of listener) to see test results. 

JMeter application
  1. By default, we should see a test plan in the left panel. Right-click to reveal a menu and select “Add” > “Threads (Users)” > “Thread Group.”

  2. On the Thread Group panel, we can change the name of the Thread Group. We also want to change the number in “Number of Threads (users)” from “1” to “2.” 

  3. To add a sampler, select “Thread Group” in the left panel, right-click to reveal the menu, and select “Add” > “Sampler” > “HTTP Request.”

  4. On the HTTP Request panel, enter “HTTPS” in the “Protocol” field, and in the “Server Name or IP” field, enter “demoblaze.com” (or an alternate site if available).

  5. To edit the Response Assertion panel, right-click on “HTTP Request” in the left panel and select “Add” > “Assertion” > “Response Assertion.” Under the “Field to Test” section, select “Response Code” from the options. Under the “Patterns to Test” section, click the “Add” button, and type “200” in the new empty field. 

  6. To add the View Results Tree, right-click on “Thread Group” and select “Add” > “Listeners” > “View Results Tree.” We don’t need to edit the default setup. Save the test by clicking the disk icon or “Ctrl+S.” 

Step 1: Adding a Thread Group panel
1 of 6

Now our test plan has four components:

  • A thread group

  • A sampler (HTTP request)

  • A response assertion

  • A View Results Tree

Running the test and analyzing results

After saving the test, we’ll run it and view the results. 

  1. Click the green arrow icon labeled “Start.” 

  2. After the test runs, click “View Results Tree.”

  3. On the “Results” console, we see either a green check arrow or red X–select the icon to review results. If our test was successful, meaning demoblaze.com was accessed by two users and the HTTP response code was 200 OK, then we see a green check mark. 

The View Results Tree panel with the response data
The View Results Tree panel with the response data

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved