This JMeter tutorial unlocks the crucial applications of the JMeter performance tool. With this quick guide to building test plans and running performance tests, you can master JMeter. You will learn how JMeter supports testing static websites and complex dynamic systems. This tutorial also discusses debugging test elements, integrations, and remote testing. You will understand how to optimise application performance using JMeter best practices and analytics.
Apache JMeter is an open-source software that testers use to evaluate the behaviour of applications and systems for various workloads. It is a performance testing tool that you can employ to identify and rectify potential application bottlenecks, boosting performance.
In this JMeter tutorial, you will learn everything you wish to know about JMeter. You will explore the JMeter test plan, its elements, and more. You will go through a step-by-step procedure for building a test plan and performing web application testing using the JMeter.
Table of Contents:
Apache JMeter is a Java-based desktop application that performs load testing on static and dynamic applications and systems. It offers many test elements that help run load tests. It provides an intuitive, user-friendly GUI for creating and running tests.
You can also run JMeter tests in non-GUI mode, either locally or remotely. JMeter offers many built-in plugins to provide flexibility in adding test elements and allows external plugins for testing.
JMeter can generate insightful reports and analytics. It helps eliminate system bottlenecks and analyse how systems work under heavy loads.
Before diving deep into the JMeter tutorial, we will learn about its features, the test plan, elements, and more.
JMeter provides a variety of test elements. They are quite handy and can save you time in writing your own Java programs for testing. Using JMeter is quite intuitive because it provides a nice GUI to create and run tests. You also can run JMeter tests in non-GUI mode. Tests can be run either locally or remotely. JMeter is designed using a plugin approach to provide flexibility in adding new features (test elements) as custom plugins.
For an in-depth learning experience, explore our JMeter Training to master performance testing and advanced JMeter techniques. |
JMeter has many incredible features. Let's take a look at some of them.
JMeter Performance testing evaluates applications to determine whether they meet the desired requirements. By identifying application loopholes, performance testing saves time and costs.
You can leverage performance testing to fix bugs in advance. Performance testing examines various elements, such as response time, resource usage, stability, speed, reliability, security, and scalability.
JMeter test plan has all the necessary elements for running performance tests and defines their structure, including the threads, samplers, listeners, and others.
A test plan has a series of steps for testing applications. Every test plan object has an object named functional testing. If you select the object, it will record the server responses for every sample so you can ensure that your configuration is perfect. It mainly helps achieve the expected results.
Well! The following section explores the JMeter test plan in detail. You will learn the various test plan elements in detail.
Learning test plan elements is the heart of the JMeter tutorial. Understanding the elements helps build test plans and run tests efficiently.
A typical test plan has one or more thread groups, listeners, logic controllers, assertions, configuration elements, and much more. Most test elements are processed in the order they appear in the test tree.
Let’s discuss the test elements in the following.
Thread Group:
The thread group element controls many threads. The Threadset is the number of threads, ramp-up period, and loop count.
The ramp-up period defines the time taken to ramp up to the execution of the total number of threads. Moreover, the loop count represents the number of times every thread can execute samplers.
Every thread in a thread group runs independently of other threads. You can use multiple threads to execute concurrent tasks.
Controllers: JMeter has two types of controllers. They are samplers and logic controllers, which are instrumental in testing.
Let’s elaborate on them in the below.
Moreover, samplers support the following protocols.
You can execute commands on the local machine or the OS Process sampler. You can also send an SQL query to a database or the JDBC Request sampler. To use your own Java classes, you can use the Java Request sampler or JUnit Request sampler for JUnit test classes.
To use a scripting language, you can use the JSR223 sampler for scripting in Java or the BSF sampler, an Apache Bean Scripting Framework.
There is a unique sampler called Test Action Sampler. It does not send any requests to the server. Instead, it can pause or stop a target thread or all threads. The Test Action sampler is used with a conditional controller.
There are many types of logic controllers. Let’s outline them in the following.
Listeners: Listeners gather data from test results. They support viewing results from GUI mode and saving results to a file in XML or CSV format. You can use the Graph Results, View Results in Table or View Results Tree listener to view detailed results.
Similarly, you can view aggregate data using the aggregate graph, aggregate report, or summary report. The Spine Visualiser in JMeter helps display the change in response time throughout the test period.
You can use the Simple Data Writer if you simply want to save results to a file without viewing it from GUI. Similarly, you can use the Save Responses as a file listener to save responses to a file. Besides, the backend listener helps to stream real-time data to external systems.
You can add listeners anywhere in the test tree. But, they only gather data from elements inside the same tree branch. You can add a Graph Results listener to show testing results. It plots testing results for all samples through visuals without consuming much resources.
Timers: Timers help to control the timing of requests within thread groups. In other words, you can use timers to delay between requests. So you can simulate real-world usage and user behaviour precisely.
There are many types of timers. The role of the timers is outlined below.
Assertions: Assertions help to check the correctness of the responses from the server. The scope of an assertion is only at the current branch in which it is defined. Descendant branches cannot access it unless it is specified.
Assertions are processed after every sampler in the same scope. If you want an assertion applied to a sampler, you can make it as a child of the sampler. You can use the Assertion Results listener to view assertion results.
There are many types of assertions, including:
Configuration Elements: Configuration elements are used to set up configurations used by samplers. They are accessible by elements inside the same tree branch, including descendant branches. They are processed at the start of the tree branch in which they are defined, no matter where they are located. One exception is the User-Defined Variables. They are processed at the start of a test run, no matter where they are located.
JMeter offers many configuration elements, as discussed below:
JMeter configuration elements include the HTTP Authorization Manager, HTTP Cookie Manager, HTTP Cache Manager, and HTTP Header Manager.
Preprocessor Elements: PreprocessorsPreprocessors are executed before samplers at the same level. You can add a preprocessor as a sampler's child to make it preprocess information before feeding it into the sampler. Preprocessors are used to modify settings before samplers run. PreprocessorsThey are executed right before timers and after configuration elements.
You can use the HTML Link Parser or HTML URL Rewriting Modifier to process HTML responses.
Post-processor Elements: Post-processors are executed right after the samplers. They extract data from the sampler responses and are executed before assertions and listeners.
Following are the examples of post-processor elements.
Okay! This section covered the JMeter elements extensively. Next, you will build a JMeter test plan, starting with JMeter installation.
First, download the JMeter software on your system. Then, follow the step-by-step procedure below to install the JMeter on your Windows machine.
java -version
Superb! You have successfully installed JMeter on your Windows machine. To start using the software, you can build a JMeter test plan. The following section discusses this in detail.
Checkout JMeter Interview Questions |
If you want to perform JMeter testing, you can either load an existing test plan or build a new one based on your requirements. This section provides the step-by-step procedure to build an effective JMeter test plan.
Let’s start now!
Starting JMeter: First, you need to start JMeter. You can do this using the command line, running JMeter.bat for Windows or JMeter.sh for Unix/Linux.
To run JMeter in non-GUI mode, you can use the following command-line options:
-n non-GUI mode
-t the test plan file with extension name jmx
-1 the result log file with extension name jtl
-j the log file
Adding and removing test elements: The JMeter GUI screen has two panels. The left panel is the test tree for a test plan, and the right panel is the configuration panel for the selected element. A new test plan starts with a Test Plan and a WorkBench.
The Test Plan is the root of a test tree. A WorkBench is a temporary place for storing test elements, not-in-use or non-test elements. You cannot save a workbench automatically.
To add a new element to the test tree, you can make it in the following way.
Another way to add an element is to choose Edit -> Add from the menu bar on the screen.
The below image depicts the same.
If you want to remove elements from the test tree, follow the steps below.
Loading and saving elements: For loading elements, you can follow the below steps.
To save elements, you can follow the steps below.
Now, JMeter will save the element and the associated child elements.
Configuring tree elements: JMeter’s right-hand frame has the controls to configure the behaviour of test elements. You must configure it based on the elements.
Saving the test plan: You must save a test plan before running it. You can follow the below steps.
Running a test plan: The following is the JMeter test plan:
When you specify the number of thread groups/threads running in a test plan, you must ensure your machine can balance the load. Adding more load will reduce the accuracy of the results.
If you want to run heavy loads, you can run them on multiple machines. It is known as remote testing. Below is the step-by-step procedure for running a test plan.
Debugging a test plan: Most test elements support JMeter's debug logging feature. The procedure below will help you with this.
Stopping a test: JMeter offers two options to stop a test: s, top, and shut down. They are on the menu.
Kudos! You have learned how to build a test plan that includes saving, running, debugging, and stopping procedures.
Now, you will learn how to create a JMeter test plan to test a web application. You can use the HTTP Request sampler to make HTTP or HTTPS requests. The HTTP Request sampler is not a browser. However, it can perform jobs a browser can do except render pages or run scripts.
It even allows you to retrieve embedded resources from web pages. You can define common settings shared among the HTTP Request samplers in the HTTP Request Defaults.
Other samplers will inherit values defined in the HTTP Request Defaults. For example, you can use the “Server Name or IP” field in the HTTP Request Defaults to specify the server to be tested. Then, you can leave that field blank in other HTTP Request samplers.
The scope of the HTTP Request Defaults is within the current branch. A web application typically needs cookie support, but you can use the HTTP Cookie Manager if required.
In the following example, four pages will be visited by each thread in random order. You can use the Random Order Controller to simulate this behaviour. The JMeter test plan is shown below:
After running this test plan, you can check the results from the two listeners defined. The following screenshot is taken from the View Results Tree:
The results tree contains a list of pages visited. A failed request is highlighted in red. You can select a page to view the request and the response.
If the response data is in HTML, you can view the rendered page by choosing HTML from the drop-down menu at the bottom of the tree. However, the page only gives you some idea about a page. JMeter supports different documents (e.g., MS Office, PDF).
You can view the text in the Document by choosing Document. View Results in Tree records requests and responses from all visited pages, which is good for checking a web application's behaviour or debugging it. You can also use it to test your JMeter test plan. However, it is not a good idea to use it during load testing since it will consume lots of resources.
Another listener in this test plan is the Summary Report. The Summary Report gives you a table view of the results. It gives you a summary report arranged by pages as table rows.
In the previous example, four pages will be visited randomly during the test. Now, you should include more pages in the test. Adding pages manually is tedious.
You can use the HTML Link Parser to add pages. The HTML Link Parser is a preprocessor that can extract links from the previous HTML response. Being followed by an HTTP request sampler and included in a loop can make everything look like a web crawler. You will add this process to the previous example.
Each thread randomly selects one of the four pages in the previous example as the starting page and crawls through the website. The Path field uses the regular expression (?i).*.html to match any HTML page in the HTML Request sampler. (?i) indicates that it is case-insensitive.
To continue crawling through the website, you add the HTTP Request sampler inside the While Controller and set the Condition field as True. To limit how long the While Controller can run, the While Controller is added as a child of the Runtime Controller. You can define the desired runtime in the Runtime field.
The following is the revised version:
Thankfully, the above two JMeter tutorials must have provided solid hands-on experience with the JMeter software. It will undoubtedly help you in the real-time work environment.
You can embrace JMeter to perform remote testing. Remote testing simplifies copying the test plan to every machine located remotely. It supports simulating heavy loads with more users.
In remote testing, one JMeter client acts as the master to control multiple JMeter instances running in remote servers. You can start a JMeter server by running the JMeter-server.bat file.
Importantly, All JMeter instances must use the same version of JMeter. Below is the step-by-step procedure for adding instances and starting remote servers.
Integrating JMeter with CI/CD pipelines assists in automating development and boosting productivity. It helps developers and testers identify issues proactively and rectify them, improving performance.
There are many advantages to integrating JMeter with ci/cd pipelines. Here are they:
You can generate a report dashboard with JMeter. It provides accurate graphs and statistics for test plans. JMeter provides the extension dashboard generator for the same. This generator processes the sample collected from the CSV files.
Usually, reports are generated at the end of the load tests or on demand. Every report provides the following metrics.
JMeter can integrate with external tools like Grafana using the influxQL language to generate effective dashboards. The Grafana dashboard will provide the following metrics.
Here are some best practices you can leverage to boost JMeter performance testing.
JMeter supports many advanced performance testing methods, including correlation, parameterisation, extractors, etc.
Let’s take a look at them below:
While performing load tests using JMeter, you may encounter many issues. In this section, let's see the common issues in JMeter and how to troubleshoot them effectively.
Thread Group Errors: If you misconfigure the thread setting, it will lead to thread group errors. Unequal load distribution and excessive resource consumption result from the thread group errors.
You can overcome these errors by making thread group settings carefully and utilising resources optimally.
JDBC Sampler Script Errors: The JDBC sampler script error occurs while running JDBC queries in test scripts. To overcome this issue, thoroughly verify SQL syntax and check the JDBC setup.
SSL Handshake Errors: These errors occur when JMeter doesn't connect with the server properly. It happens because of the certificate problems.
To avoid these errors, you must carefully verify the server certificates and examine protocol interoperability.
Sure! We hope this JMeter tutorial has given you a clear picture of the common issues in JMeter testing and how to eliminate them effectively.
Apache JMeter 5.6.3 is the newest version of JMeter, released in January 2024. You must have Java8 or above installed on your machine to install it.
Yes, learning JMeter is easy. If you strongly desire to learn and devote your time, then learning JMeter is a walk in the park. MindMajix offers hands-on JMeter training by certified trainers. Beginning and experienced learners can join the course and sharpen their testing skills.
Learning JMeter is a good choice since it provides many job opportunities in top companies like TCS, Accenture, Capgemini, Wipro, IBM, etc. AmbitionBox says performance testers' salaries range from 4 LPA to 9 LPA in India. According to Talent.com, they earn a yearly salary from 92k to 130k USD. These figures show that making a career in JMeter is rewarding and promising.
Yes, we can use JMeter for API testing. JMeter offers many built-in plugins and supports external plugins. The plugin manager plays a crucial role in JMeter integrations so that we can use JMeter for smooth and quick API testing.
To show testing results, we add a Graph Results listener. The Graph Results listener plots testing results for all samples. It is good for showing the progress of testing visually. But, it does consume more resources. Usually, this is used in testing or debugging a test plan with a small load.
Long story short, JMeter is a performance-testing tool for applications, databases, and networks. To run tests, we need to create a test plan that includes various test plan elements.
In this JMeter tutorial, you will explore its features, including creating test plans, testing applications, and more. If you want to explore JMeter further, we can help you.
MindMajix offers top-class JMeter training with industry experts. At the end of the training, you can gain a comprehensive knowledge of JMeter and hands-on skills in performance testing. You will undoubtedly advance your career with flying colours.
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
JMeter Training | Nov 19 to Dec 04 | View Details |
JMeter Training | Nov 23 to Dec 08 | View Details |
JMeter Training | Nov 26 to Dec 11 | View Details |
JMeter Training | Nov 30 to Dec 15 | View Details |
Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.