JMeter Tutorial

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.

Rating: 4.5
14750

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:

What is JMeter?

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 Features:

JMeter has many incredible features. Let's take a look at some of them.

  • JMeter supports external tools and extensions widely. For example, it supports plugins to provide additional capabilities to JMeter. You can use the JMeter plugins manager to install and manage the plugins.
  • It supports distributed testing for a high volume of workloads. So you can execute a test plan across multiple machines. It requires setting a master-slave configuration.
  • It allows for storing tests in multiple formats, including CSV, JTL, XML, and JSON.
  • It provided a user-friendly, intuitive interface, simplifying user and software interactions.
  • It supports cross-platform. So JMeter can work on MacOS, Linux, etc., platforms seamlessly.
  • It supports distributed testing, so you can simultaneously run JMeter on multiple machines.

JMeter Performance Testing

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:

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.

MindMajix Youtube Channel

Test Plan Elements:

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.

  • Samplers: Samplers are used to send requests to a server and wait for responses. They generate different types of requests as follows:
    1. HTTP request – It sends HTTP Requests to web servers
    2. FTP request -  It sends FTP Requests to web servers
    3. JMS request – It sends and receives JMS messages
    4. SOAP request – It helps exchange information between applications
    5. XML-RPC request – It supports communication in web services.

Moreover, samplers support the following protocols.

    1. TCP – It is a communication protocol used on the internet
    2. SMTP – It supports sending and receiving emails over a network
    3. POP3 – It allows users to access their emails from a server
    4. IMAP -  It will enable accessing mail from mail servers from anywhere
    5. LDAP –  It supports managing directory services over the internet

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.

  • Logic Controllers: Logical controllers control the execution of samplers within a thread group. In other words, they can control the order in which samples are defined in the test tree.

There are many types of logic controllers. Let’s outline them in the following.

    • Loop Controller — This controller allows you to perform looping operations in JMeter and supports repeating requests a certain number of times.
    • If Controller — You can use this Controller for decision-making operations.
    • Simple Controller —You can use this Controller to execute a group of elements in a specific order.
    • Random Order Controller — This Controller executes elements in random order.
    • Interleave Controller — It supports executing elements per iteration. You can use alternating elements for each iteration.
    • Once Only Controller — This Controller helps process elements once per thread.
    • Include Controller—It helps to include a test fragment created through the test fragment element. You can break codes into fragments or modules to structure your tests better.
    • Module Controller—This Controller helps include test fragments located in any thread group or the WorkBench. You can include any fragment under a logic controller even if it is disabled.
    • Throughput controller — It controls the rate of requests
    • Transaction controller — This Controller measures the total time of a group of requests.

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.

    • The Constant Timer - You can use this timer to make a constant delay between requests.
    • Gaussian Random Timer – It creates a delay based on the Gaussian distribution.
    • Uniform Random Timer or Poisson Random Timer – It creates a delay with a uniform distribution.
    • Precise Timer – It controls the accurate time between requests

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:

    • Response Assertion – It examines the contents of responses. For example, it checks whether a string is present in the response.
    • Duration Assertion – It checks whether you have received the response within a specific time.
    • Size Assertion – It verifies the size of each response

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:

    • HTTP Request defaults – It defines the default settings for HTTP requests
    • CSV data set configuration – It helps to parameterise requests to read data from CSV files.
    • User-defined variables – It helps to define custom variables in test plans
    • JDBC connection configuration – It helps to define database connection settings. It supports the JDBC request sampler.
    • Counter configuration element –  You can configure counters with this element.

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.

    • Regular Expression Extractor – This tool helps extract values from a response and assign the result to a variable for later use.
    • JSON extractor – It assists in extracting data from JSON responses
    • XPath extractor – It helps in extracting data from XML responses. 

Okay! This section covered the JMeter elements extensively. Next, you will build a JMeter test plan, starting with JMeter installation.

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.

  1. First, make sure whether your system is installed with Java 8 or above
  2. Open the command prompt in your system and use the command below. java -version
  3. If your system is installed with Java, you will get the response in the image below.
  4. Next, you can use the below link to download the latest JMeter software (Apache JMeter 5.6.3)
  5. Open the bin folder in the downloaded folder
  6. Double-click the JMeter.bat file, as shown in the image below.
  7. Now, your system is installed with the JMeter software.

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

JMeter Tutorial: How to Create a Test Plan in JMeter

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.

  1. Right-clicking on an element
  2. Choosing the Add option.

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.

  1. right click on the element
  2. select the remove option

Loading and saving elements: For loading elements, you can follow the below steps.

  1. Right-click on the tree element
  2. Select merge option
  3. Choose the file where the elements are saved

To save elements, you can follow the steps below.

  1. Right-click on the element
  2. Select the ‘save selection as..’ option

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.

  1. Go to the file menu
  2. Select the ‘save’ or ‘save test plan as…

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.

  1. Run a test plan through the Run menu or the toolbar.
  2. You can check the status of the running test plan from the upper-right corner.                                                                  
  3. The green square icon indicates that a test plan is running. The yellow triangle icon with a number is the error counter.
  4. The JMeter log file JMeter.log is in the bin directory by default.
  5. To see the logging screen from the GUI, you can toggle it on and off by clicking on the yellow triangle icon
  6. You can choose the Options menu -> Log Viewer to accomplish the previous step
  7. 5/5 on the screen shows that the total number of threads is five, and all five are running.
  8. Select the ‘Clear All’ option from the Run menu to clear the test plan's results.
  9. Stop or shut down a running test using the Run menu or the toolbar.
  10. The difference between stop and shutdown is that threads stop immediately for the stop option. They stop at the end of the current work for shutdown.
  11. You can use shutdown in non-GUI mode as well.

Debugging a test plan: Most test elements support JMeter's debug logging feature. The procedure below will help you with this.

  1. Select a test element to enable debug logging
  2. Next, navigate to the ‘Help’ menu and choose the ‘Enable debug’ option.
  3. If you want to disable logging, then choose the ‘Disable to debug’ option
  4. If you want to view debug logging, then open JMeter.log under the bin directory
  5. Or else, you can enable ‘Log Viewer’ before you run it.

Stopping a test: JMeter offers two options to stop a test: s, top, and shut down. They are on the menu.

  1. Stop: This option stops the thread instantly. It will also check whether all the threads are stopped within the default time.
  2. Shutdown: this option allows JMeter to stop the test only at the end of the current task.

Kudos! You have learned how to build a test plan that includes saving, running, debugging, and stopping procedures.

JMeter web application Testing:

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.

JMeter Remote Testing:

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.

  • Navigate to the JMeter client.
  • Add remote servers into the property remote_hosts
  • Now you can start the JMeter client
  • Then, load the test plan.
  • Select the Run menu -> Remote Start
  • Select Remote Start All in the JMeter panel

JMeter CI/CD Pipeline:

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:

  • Detecting issues in advance helps to improve development performance
  • You can get the performance test results for every code change
  • You can run performance tests consistently by eliminating differences between development, staging and production environments.
  • JMeter minimises the manual efforts in CI/CD pipelines.

JMeter Report Dashboard:

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.

    • APDEX – Application performance index
    • a request summary graph
    • a statistics table
    • an error table
    • zoomable chart
  • Integrating with external tools for report dashboard

JMeter can integrate with external tools like Grafana using the influxQL language to generate effective dashboards. The Grafana dashboard will provide the following metrics.

    • Number of users
    • Transactions count
    • Errors count
    • Errors rate
    • Errors by transaction

JMeter Best Practices:

 Here are some best practices you can leverage to boost JMeter performance testing.

  • Using the latest JMeter version helps to derive better test results
  • Using the correct number of threads improves the efficiency of the test execution
  • You need to save the cookie manager and authorisation manager at the suitable locations
  • Using the HTTP test script recorder helps to package all test samples in a single controller
  • Using user variables, you can use different values for different users or threads

Advanced Performance Testing Using JMeter

 JMeter supports many advanced performance testing methods, including correlation, parameterisation, extractors, etc.

 Let’s take a look at them below:

  • Parameterisation: In this method, you will use variables to simulate real-world data in JMeter. It helps generate data dynamically. For example, you can use variables for passwords, user names, etc. Thus, you can simulate system behaviour for different profiles and scenarios.
  • Correlation: In this method, JMeter captures dynamic values such as tokens, Session IDs, and timestamps from server responses. It stores the values in variables, which you can correlate with subsequent requests. It helps simulate user sessions and gain more accurate test results.

Common Issues in JMeter Performance Testing and Troubleshooting:

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.

Summary:

  • JMeter is a Java-based performance-testing tool
  • We can employ it to test the performance of applications, databases and other systems
  • It helps to examine server responses, identify bottlenecks in processes, and optimise the performance
  • We can create test plans, add  and configure test elements, and run tests with JMeter
  • Thread groups, samplers, assertions, timers, and controllers are some of the elements of the JMeter test plan.
  • JMeter supports distributed testing so you can distribute loads across multiple systems and test them, enhancing efficiency
  • JMeter supports visualising test results through graphs and charts

Frequently Asked Questions

1. What is the latest version of JMeter?

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.

2. Is learning JMeter easy?

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.

3. What is the difference between HP LoadRunner and JMeter?

  • They have different user interfaces and workflow.
  • LoadRunner supports a wide range of protocols, whereas JMeter supports a limited number of protocols without plugins.
  • Setting up LoadRunner is easy, but it is tricky for JMeter.

4. Is learning JMeter a good choice?

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.

5. Can you use JMeter for API testing?

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.

Conclusion:

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.

Job Support Program

Online Work Support for your on-job roles.

jobservice

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:

  • Pay Per Hour
  • Pay Per Week
  • Monthly
Learn MoreGet Job Support
Course Schedule
NameDates
JMeter TrainingNov 19 to Dec 04View Details
JMeter TrainingNov 23 to Dec 08View Details
JMeter TrainingNov 26 to Dec 11View Details
JMeter TrainingNov 30 to Dec 15View Details
Last updated: 15 Nov 2024
About Author

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.

read less