JMeter Tutorial for Beginners

JMeter Tutorial for Beginners, JMeter Installation, JMeter Tool Fundamentals, JMeter Testing Process, and Performance Testing using JMeter.

Apache Jmeter is a popular open-source performance testing tool, a 100% pure Java application designed to load test functional behavior and measure performance.

It was originally designed for testing Web Applications but has since expanded to other test functions.

Apache JMeter supports conducting Web page, Database server, FTP, JMS, and Web Services Performance Testing.

JMeter Tutorial for Beginners

1. Introduction Performance Testing

What is Performance Testing?
Independent Testers conduct Performance Testing at System Testing Level using Black Box Test Design Techniques.

Types of Performance Testing
We have different types of performance testing like Load Testing, Stress Testing, Spike Testing, Endurance Testing, and Volume Testing.

How to conduct Performance Testing?
Generally, Software Testing can be done in two ways, 1) Manual Testing, 2) Automated Testing, but Manual Testing is impractical for Performance Testing and Automated Testing is only possible.

Performance Test Tools
We have several test tools are available for performance Testing, Apache JMeter, Micro Focus LoadRunner, IBM RPT, Silk Performer, WebLoad, and NeoLoad, etc…

Performance Test Life Cycle

Important Steps in Performance Test Life Cycle are:

Identify the Testing Environment, Identify Performance Metrics, Plan and Design Performance Tests, Configure the Test Environment, Implement your test design, Run / Execute Tests and Analyze, tune and retest.

2. Introduction to Apache JMeter

What is Apache JMeter?
Apache JMeter is an open-source, 100% Java-based application with a graphical user interface.

Advantages and Disadvantages of JMeter
Open Source, Ease of Use, Platform Independent, and Multi-Protocol Support, etc…
Web Application only, Memory Consumption, and Lack of support for JavaScript…

JMeter vs LoadRunner

How does JMeter Work?

Installation of JMeter
Download & Install Java Software, Set JAVA_HOME Environment Variable, Verify Java Installation,
Download Jmeter and unzip and Launch / Start JMeter.

3. Elements of JMeter Test Plan

Thread Group
A Thread Group is a set of threads executing the same scenario. Virtual user groups are represented by Thread Groups.

Controllers
JMeter has two types of Controllers: Samplers and Logical Controllers. These drive the processing of a test.

Controllers – Samplers
Samplers tell JMeter to send requests to a server and wait for a response.
Ex: FTP Request, HTTP Request, JDBC Request and JMS request etc.

Controllers – Logic Controllers
Logic Controllers let you customize the logic that JMeter uses to decide when to send requests.

Listeners
Listeners are the JMeter component that displays test results.

Timers
By default, a JMeter thread executes samplers in sequence without pause. We recommend that you specify a delay by adding one of the available timers to your Thread Group.

Assertions
The assertion in JMeter is used to validate the response of the request, that you have sent to the server. The assertion is a process where you verify the expected result with the actual result of the request at run time.

Configuration Elements
Config elements in JMeter are used to configure or modify the sampler requests made to the server. They do not send requests, configure or modify the sampler requests.

Pre-Processor Elements
PreProcessors are JMeter elements that are used to execute actions before the sampler requests are executed in the test scenario.

Post-Processor Elements
A Post-Processor executes some action after a Sampler Request has been made. If a Post-Processor is attached to a Sampler element, then it will execute just after that sampler element runs.

Execution Order of Test Elements:

0. Configuration elements
1. Pre-Processors
2. Timers
3. Sampler
4. Post-Processors (unless SampleResult is null)
5. Assertions (unless SampleResult is null)
6. Listeners (unless SampleResult is null)

4. Building a Test Plan

A test plan describes a series of steps JMeter will execute when run. A complete test plan will consist of one or more Thread Groups, logic controllers, sample generating controllers, listeners, timers, assertions, and configuration elements.

• Add and Remove Elements

• Load and Save Elements

• Configure the Tree Elements

• Save and Run the Test Plan

5. Recording Tests Using JMeter

• Creation of Thread Group

• Adding HTTP Proxy Server

• Configuring HTTP proxy server

• Configuring the browser for recording the test script

• Capturing the test steps using JMeter

6. Enhancements in Test Scripts

• Parameterization

• Correlations

• Validations

• Debugging Script

• Assertions

• Error Handling Etc…

7. JMeter Result Analysis

• Running a test plan is only 50% of the performance testing task.

• The most challenging part of the performance testing process is the analysis of test results and the identification of bottlenecks.

• Listeners are the most important part of JMeter’s test plan as users can only see the results of their samplers by making use of listeners.

8. Running Multiple Scripts with JMeter

• Creating multiple test thread groups.

• Calling the multiple thread groups from a test plan.

• Configuring the threads groups with respective user numbers and ratios.

• Running the load test for multiple thread groups from a Single Test.

• Analyze the user group-specific issues.

• Analyze the Test plan-specific issues for all user groups.

9. Different Types of JMeter Test Plans

JMeter – Web Test Plan (HTTP Request)
Build a simple test plan which tests a web page. We write a test plan in Apache JMeter so that we can test the performance of the web page.

JMeter – Database Test Plan (JDBC Request)
Create a test plan to test the database server.

JMeter – FTP Test Plan
Create a Test Plan to test the FTP site.

JMeter – Webservice Test Plan (SOAP/XML-RPC Request)
Create a Test Plan to test a web service

JMeter – JMS Test Plan
Create a test plan to test Java Messaging Service (JMS).

10. Jmeter Distributed (Remote) Testing

Distributed testing enables having a local JMeter (master) that handles the test execution, together with multiple remote JMeter instances (slaves) that will send the request to our target server.

0. Configure the nodes

1. Start Servers

2. Add the server IP to your client’s Properties File

3. Start the JMeter Client from a GUI client to check configuration

4. Start the JMeter from a non-GUI Client

11. JMeter Functions, Variables, and Regular Expressions

JMeter Functions can be used for many different operations, including inputting information from a file, performing math calculations and value generation, processing strings, evaluating JMeter variables, working with JMeter properties, and executing scripts like Javascript or BeanShell script.

Variables can store some values which you need in different places of your test.

Regular Expressions are a tool used to extract a required part of the text by using advanced manipulations.

• List of Functions

• Where to Use Functions And Variables

• Referencing Variables and Functions

• JMeter Regular Expressions

12. JMeter Best Practices

Limit the Number of Threads
Your hardware capabilities, as well as the Test Plan design, will both impact the number of threads you can effectively run with JMeter.

Reducing resource requirements
Use non-GUI mode, use as few Listeners as possible; only save the data that you need, use as few Assertions as possible.

Use Variables
This functionality allows changing parameters in multiple places of the Test-plan.

Distributed Testing
Once you reach the limits of one machine, you can switch to distributed or remote testing.

BeanShell server
The BeanShell interpreter has a very useful feature – it can act as a server, which is accessible by telnet or http.

Parameterizing tests
Often it is useful to be able to re-run the same test with different settings. For example, changing the number of threads or loops, or changing a hostname.


1. Introduction to Performance Testing

i. What is Performance Testing?

Performance Testing is a non-functional software testing type that determines how the stability, speed, scalability, and responsiveness of an application holds up under a given workload.

ii. Subsets of Performance Testing

a. Load Testing:
It’s a type of performance testing that simulates a real-world load on software applications. An increasing number of concurrent users, transactions and check the behavior of the application under test.

Ex: Login to Xyz Application with increasing multiple users Load (2000, 3000, 4000….)(Expected: Login within 6 Seconds) – Load Testing

b. Stress Testing
It involves testing an application under extreme workloads to see how it handles high traffic or data processing. The objective is to identify the breaking point of an application.

Ex: Login to Xyz Application with maximum load and more than the capacity (10000, 11000…) -Stress Testing

c. Spike Testing
Tests the software’s reaction to sudden large spikes in the load generated by users.

Ex: Login to Xyz Application with sudden increments/decrements of Load (1000, 7000, 2000…) – Spike Testing

d. Endurance Testing
It is done to make sure the software can handle the expected load over a long period
of time.

Ex: Login to Xyz Application with multiple users over a period of Time
(5000 Users for 2 Hours/repeat Login operation for 5000 users for 2 hours of Time) – Endurance Testing

e. Data Volume Testing
Under Volume Testing large no. of. Data is populated in a database and the overall software system’s behavior is monitored.

iii. How to conduct Performance Testing?

Generally, Software Testing can be done in two ways,

a. Manual Testing
b. Automated Testing

Ex: We can conduct Functional Testing manually or using Test Tools like UFT or Selenium etc…

But Manual Testing is impractical for Performance Testing, Automated Testing is only possible.

iv. Performance Test Tools

Popular Test Tools for Performance Testing:

a. Micro Focus LoadRunner
LoadRunner is a commercial software test tool from Micro Focus. HP acquired LoadRunner as part of its acquisition of Mercury Interactive in November 2006, In Sept 2016, Hewlett Packard Enterprise announced it is selling its software business, including Mercury products, to Micro Focus. As of 01-Sept-2017, the acquisition was complete.

LoadRunner supports Computer and Mobile Applications performance testing.

b. Apache JMeter
The Apache JMeter application is open-source software, a 100% pure Java application designed to load test functional behavior and measure performance.

c. IBM RPT
Rational Performance Tester is a tool for automated performance testing from the Rational Software division of IBM.

d. Silk Performer
Silk Performer is a software performance testing tool across the web, mobile, and enterprise applications. It was originally developed by Segue Software which was acquired by Borland in 2006. Borland was acquired by Micro Focus International in 2009.

e. WebLoad
WebLOAD is load testing tool, performance testing, stress test web applications. This web and mobile load testing and analysis tool is from RadView Software.

f. NeoLoad:
NeoLoad is a performance test tool of web and mobile applications.

g. OpenSTA

v. Performance Test Process (Automated Test Process)

Important Steps:

a. Identify the Testing Environment.

Identify the hardware, software, network configurations, and tools for conducting Performance testing.

b. Identify Performance Metrics.

Identify metrics such as response time, throughput and constraints and identify what is the success criteria for performance testing.

c. Plan and Design Performance Tests.

Identify performance test scenarios that take into account user variability, test data, and target metrics.

d. Configure the Test Environment.

Prepare the elements of the test environment and instruments needed to monitor resources.

e. Implement your test design.

Record Test Scripts, Create and Apply multiple users (Virtual users) Load

f. Execute Tests.

Run Performance Tests

g. Analyze, tune, and retest.

Analyze Test Results, then fine-tune and test again to see if there is an improvement or decrease in performance.


2. Introduction to Apache JMeter.

i. What is Apache JMeter?

Apache JMeter is an open-source, 100% Java-based application with a graphical user interface. It is designed to analyze and measure the performance and load functional behavior of web applications and a variety of services.

JMeter is mainly used for testing Web applications but currently, it is applicable for JDBC database connections, Web services, generic TCP connections, and OS native processes.

You can perform various testing activities like Performance, Load, Stress, Regression, and Functional testing, in order to get accurate performance metrics against your web server.

JMeter is not a browser and it doesn’t render html pages as any browser does, rather it works on protocol level.

Functional Testing with JMeter
JMeter was originally built to provide an open-source solution for performance testing. However, JMeter can also be used to perform functional tests on an application’s backend. For example: with JMeter, you can test part of your user registration functionality by testing your system’s APIs and verifying that users are successfully created within your database.

ii. Features and Drawbacks of using JMeter

Features of using JMeter:

a. Open Source: JMeter is open-source software, it can be downloaded free of cost. It is also a 100% pure Java application. The developer can use its source code, can modify and customize it as per their requirement. They can also contribute their code to make a better JMeter.

b. Ease of Use: The user can install and use JMeter easily. Just download it from the internet, install and run it. As a pure Java desktop application, it comes ready to use with default settings. It does not require you to have any specific skills or domain knowledge to use it.

c. Platform Independent: JMeter is developed in Java, which is the most popular programming language in the world. Therefore, it can run in any OS be it Windows, Linux, or Mac.

d. Robust Reporting: JMeter can generate effective reporting. The test result can be visualized by using Graph, Chart, and Tree View. JMeter supports different formats for reporting like text, XML, HTML, and JSON.

e. Flexibility: You can customize JMeter as per your requirement, you can save the effort of executing test cases manually.

f. Multi-Protocol Support: JMeter supports several protocols like HTTP, FTP, SOAP, JDBC, JMS, and LDAP. It can also be used for testing the performance of your database.

Drawbacks of using JMeter:

a. Web Application only: JMeter is a good tool for testing web applications but it is not a suitable tool for testing desktop applications.

b. Memory Consumption: JMeter can simulate heavy load and visualize the test report. This may consume lots of memory and can lead out of memory under heavy load.

c. Lack of support for JavaScript: JMeter is not a browser, so it cannot run JavaScript in the web application. It has limited support for processing JavaScript or Ajax, this may affect the accuracy of the simulation.

iii. JMeter vs LoadRunner

JMeter and LoadRunner are two different performance testing tools.

Apache JMeter:

a. Open Source Software

b. Limed number of protocol support

c. Limited Technical support

d. JMeter is technically less proficient.

e. JMeter has an unlimited load generation capacity.

Micro Focus LoadRunner:

a. LoadRunner is a Commercial tool

b. It supports more number of protocols

c. Since It is a Commercial Tool it has rich Technical Support

d. LoadRunner is highly developed and complex.

e. LoadRunner has a limited load generation capacity

iv. How does JMeter Work?

• JMeter creates requests and sends them to the server just like a web browser requesting a page

• It receives the response from the server, collects them, and visualizes those details in a chart or graph.

• It processes the response from the server.

• It generates the test result in several formats such as text, XML, JSON. Then the tester can analyze the data

v. Installation of JMeter

Steps to setup JMeter on Windows OS:

Step 1: Download & Install Java Software

JMeter is a pure Java desktop application, it requires a fully compliant JVM. You can download and install the latest version of Java(JDK)

Step 2: Set JAVA_HOME Environment Variable

The JAVA_HOME environment variable points to the directory where the Java run-time environment (JRE) is installed on your computer.

Step 3: Verify Java Installation

After Java installation, you can use the following procedure to check whether Java JDK is installed successfully in your system

In Window/Linux, go to Terminal
Enter command java -version

Step 4: Download Jmeter and unzip

Installation of JMeter is easy and simple. You simply unzip the zip/tar file into the directory where you want JMeter to be installed.

Step 5: Launch JMeter

We can start JMeter in three modes

a. GUI Mode
b. Server Mode
c. Command Line Mode

Step 6: Start JMeter in GUI Mode

On Windows, just run the file /bin/jmeter.bat to start JMeter in GUI mode.


3. Elements of JMeter

Elements of JMeter Test Plan:

Different parts or components of JMeter are called JMeter Elements they co-relate with each other but designed for different-different purposes.

Before start working on Jmeter Tool, it is important to know all components or Elements of Jmeter with a full detailed description.

Common Elements in JMeter are,

i. Test Plan
ii Thread Group
iii Controllers (Samplers, Logical Controllers)
iv Listeners
v. Timers
vi Assertions
vii Configuration Elements
viii Pre-Processor Elements
ix. Post-Processor Elements

i. Test Plan:

A test plan is the top-level element of JMeter, explains the sequence of steps executes at run time. A test plan made up of Thread Groups, Sampler, logic controller/s, listener/s, timer/s, assertions/, and configuration elements. Each Sampler can be preceded by one or more Pre-processor elements, followed by a Post-processor elements, and/or Assertion elements.

Test Plan saves in Java Management Extensions (JMX) format.

ii. Thread Group

A Thread Group is a set of threads executing the same scenario. It is the base element for every JMeter test plan.

There are multiple thread groups available that can be configured to simulate how the users interact with the application, how the load is maintained and over what period of time.

Thread Group options:

a. Number Of Threads: It represents the total number of virtual users performing the test script execution.

b. Ramp-Up Period (in seconds): It tells JMeter how long to take to reach the full number of threads. For example, if you have 100 users with a ramp-up period of 50 seconds, JMeter will take 50 seconds to get all 100 threads running, adding 2 threads per second.

c. Loop Count: It is the number of executions for the script. For example, if the loop count is 2 and number of threads is 100 then the script will run 200 times. If the loop count is set “forever” then new threads will keep starting until the tests are stopped.

d. Delay Thread Creation Until Needed: If this option is checked, the ramp-up delay and startup delay are performed before the thread data is created. If not checked, all the data required for the threads is created before starting the execution of a test.

e. Scheduler: This schedules the tests. You can set custom duration and startup delay to create the threads in this section.

iii. Controllers

JMeter has two types of Controllers: Samplers and Logical Controllers. These drive the processing of a test. Samplers tell JMeter to send requests to a server.

a. Samplers

Samplers tell JMeter to send requests to a server and wait for a response. They are processed in the order they appear in the tree. Controllers can be used to modify the number of repetitions of a sampler.

JMeter samplers include:

FTP Request
HTTP Request (can be used for SOAP or REST Webservice also)
JDBC Request
Java object request
JMS request
JUnit Test request
LDAP Request
Mail request
OS Process request
TCP request

b. Logical Controllers

Logic Controllers let you customize the logic that JMeter uses to decide when to send requests. Logic Controllers can change the order of requests coming from their child elements. They can modify the requests themselves, cause JMeter to repeat requests, etc.

Logic Controllers of JMeter provide,

Runtime Controller
IFController
Transaction Controller
Recording Controller
Simple Controller
While Controller
Switch Controller
ForEach Controller
Module Controller
Include Controller
Loop Controller
Once Only Controller
Interleave Controller
Random Controller
Random Order Controller
Throughput Controller

c. Test Fragments

The Test Fragment element is a special type of controller that exists on the Test Plan tree at the same level as the Thread Group element. It is distinguished from a Thread Group in that it is not executed unless it is referenced by either a Module Controller or an Include_Controller.

This element is purely for code re-use within Test Plans

iv. Listeners

Listeners show the results of the test execution. They can show results in a different format such as a tree, table, graph or log file

Listeners can be added anywhere in the test, including directly under the test plan. They will collect data only from elements at or below their level.

Different Listeners provided by JMeter are:

View Results in Table
View Results Tree
Aggregate Report
Aggregate Graph
Assertion Results
Backend Listener
BeanShell Listener
Graph Results
Mailer Visualizer
Monitor Results
Response Time Graph
Save Response to a file
Simple Data Writer
Summary Report

v. Timers

By default, a JMeter thread executes samplers in sequence without pause. We recommend that you specify a delay by adding one of the available timers to your Thread Group. If you do not add a delay, JMeter could overwhelm your server by making too many requests in a very short amount of time.

Timers provided by JMeter are:

Constant Timer
Gaussian Random Timer
Uniform Random Timer
Constant Throughput Timer
Synchronizing Timer
JSR223 Time
BeanShell Time
BSF Time
Poisson Random Time

vi. Assertions

Assertions are used to validate the sampler response received from the server. In order to test a sampler response, we add different assertions to the sampler. If an assertion fails, the sampler response is marked as a failure and the same gets reflected in the test results.

Different Assertions provided by JMeter are:

Response Assertion
The response assertion used in test scripts to validate a pattern in the response body, header, code, message etc. There are different pattern matching rules to validate the response like-

Contains – If the response text contains the regular expression to be matched
Matches – If the whole response text matches the regular expression
Equals – If the whole response text matches the pattern(not regular expression but the pattern string)
Substring – If the response text contains the pattern(not a regular expression)
Not – To check that the pattern is not present in the response-text

HTML Assertion
Size Assertion
Compare Assertion
BSF Assertion
Duration Assertion
XML Assertion
The XML assertion is used to validate that the response follows a valid XML syntax.
XML Schema Assertion
MD5Hex Assertion
SMIME Assertion
JSR223 Assertion

vii. Configuration Elements

Configuration Elements in JMeter are used to configure or modify the sampler requests made to the server. These elements are added at the same or higher level of the samplers they want to configure.

Configuration Elements that JMeter provides:

Counter
CSV Data Set Config
FTP Request Defaults
HTTP Authorization Manager
HTTP Cache Manager
HTTP Cookie Manager
HTTP Proxy Server
HTTP Request Defaults
HTTP Header Manager
Java Request Defaults
Keystore Configuration
JDBC Connection Configuration
Login Config Element
LDAP Request Defaults
LDAP Extended Request Defaults
TCP Sampler Config
User-Defined Variables
Simple Config Element
Random Variable

viii. Pre-Processor Elements

A Pre-Processor executes some action prior to a Sampler Request being made. If a Pre-Processor is attached to a Sampler element, then it will execute just prior to that sampler element running.

A Pre-Processor is most often used to modify the settings of a Sample Request just before it runs, or to update variables that aren’t extracted from response text.

ix. Post-Processor Elements

A Post-Processor executes some action after a Sampler Request has been made. If a Post-Processor is attached to a Sampler element, then it will execute just after that sampler element runs.

A Post-Processor is most often used to process the response data, often to extract values from it.

The execution order of Test Elements

0. Configuration Elements
1. Pre-Processors
2. Timers
3. Sampler
4. Post-Processors (unless SampleResult is null)
5. Assertions (unless SampleResult is null)
6. Listeners (unless SampleResult is null)


 

Follow me on social media:

1 thought on “JMeter Tutorial for Beginners”

Comments are closed.