Load Testing Using JMeter
Performance is an important factor to consider when building both mobile and web applications to verify whether the product meets the required performance. We need a well designed tool to test and JMeter works best in this.
What Is JMeter
Apache JMeter is a java application designed to load test functional behavior and measure performance. It’s used to simulate a heavy load on a server, group of servers or objects to test its strength or analyze overall performance under different load types.
What is Performance Testing
A type of software testing to ensure applications will perform well under their expected workload.
Types of Performance Testing
1.Load testing — measures system performance as the workload increases.Confirms that the system can handle the required number of users and still operate at a high performance.
2. Stress testing — measures system performance outside of the parameters of the normal working conditions. The goal is to measure the software stability.
3. Scalability testing — used to determine if software is effectively handling increasing workloads, it’s done by adding to the user load or data volume.
4. Volume testing — checks that the software can handle and process a large amount of data at once without breaking, slowing down or losing information.
Advantages Of JMeter
1.Open source — JMeter is an open source software, it can be downloaded free of cost , one can use its source code, can modify and customize it as per their requirement.
2.Platform Independent — since it is 100% java-based , it is a platform-independent and can run on multiple platforms.
3.Customizable -since JMeter is open source, one can customize its source code as per their specific requirements.
4.Visualize Test Result — tests results can be displayed in a different format e.g tables, graphs, texts or trees
How To Install JMeter on Ubuntu
Step 1 — Installing Java
apt-get install openjdk-11-jdk -y
Set JAVA_HOME PATH
All you have to do is to set the “JAVA_HOME” and “PATH” environment variables and then you are done
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
To check whether your JAVA_HOME path has been successfully saved,run the following command to check
echo $JAVA_HOME
The value stored in the JAVA_HOME will be displayed on the terminal
Add JAVA bin directory to the PATH variable
We need to update the PATH variable like the JAVA_HOME path
export PATH=$PATH:$JAVA_HOME/bin
The command will add the java directory to the existing PATH variable
echo $PATH
You can check the path variable by running the command above
Verify JAVA setup
java -version
Step 2 -Install Apache JMeter
You can download it with the following command
wget https://downloads.apache.org//jmeter/binaries/apache-jmeter-5.3.zip
Once downloaded, unzip the downloaded file with the following command
unzip apache-jmeter-5.3.zip
Step 3 -Launch the Apache JMeter Application
-Change the directory to the JMeter
cd apache-jmeter-5.3/bin
-Start the JMeter application with the following command
./jmeter
You should see the JMeter interface:
On windows: How to install JMeter on Windows
JMeter Elements
Components of JMeter are called elements and every elements and each element has a specific purpose
1.Test plan -the top level body of JMeter,it explains the sequence of the steps executed at run time. A final test plan is made up of one or more thread groups, sampler, logic controllers ,listeners, timers, assertions and configuration elements.
2.Thread Group- the initial stage of the test plan. The name thread groups represents a group of threads. Under this group each thread represents one real user request to the server
3.Samplers — they allow JMeter to send different types of requests to a server.They are the actual requests. Each sampler generates one or more sample results.
4. Listeners — they facilitate viewers to view samplers result in the form of tables, graphs, texts or trees.
How JMeter works
1.JMeter creates requests and sends them to server requesting a page.
2.It receives the response from the server, collects them and visualized those details in a chart or graph.
3.it processes the response from the server.
4. It generates the test result in several formats e.g text,JSON. Then the tester can analyze the data.
Testing Example
A.Adding Users
1.Adding a thread group element , the element tells JMeter the number of users you want , how often users should send requests and how many requests they should.
1.Provide a name for the thread group.
2.set the number of users (threads).
3. Enter a value in the loop count field, it tells JMeter how many times to repeat.
-right click on the the test plan button, add menu and select add then threadgroup.
B.Adding Default HTTP Request Properties
.Defining the tasks that the users will perform and specify settings for HTTP requests
- it defines the default values that the HTTP request elements use
-select the thread group element, right click to get the add menu select add, config element ,HTTP Requests Default and you will see a similar interface
C.Adding Cookie Support
- next we will add HTTP Cookie Manager to each thread group in the test plan to ensure that each thread gets its own cookies but shared across HTTP requests.
- to add the HTTP cookie Manager, select the thread group,and choose Add → Config Element → HTTP Cookie Manager.
D. Adding HTTP Request
. We will make 1 HTTP request, accessing a home page
.Right click threadgroup Add → Sampler → HTTP Request
E.Adding A Listener To View Store The Test Results
- The final element is a listener,responsible for storing all the results of the HTTP requests
. Right click threadgroup (Add → Listener → View Results Tree)
Here are some of the resources I used:
Happy testing!