Due to immense growth of web-based applications, testing these web applications has now gained a lot of importance—specifically, performance testing of applications such as e-commerce, web services, and etc. because of the volume of the consumers who use these applications simultaneously. In this article, we will have a look into how to do performance testing of a web application using JMeter, an open source performance testing tool.
The Apache JMeter is an open source testing tool used to test the performance of the application when it is under heavy load. This can be used to test both static as well as non-static data. It puts a heavy load on server, helps in testing the performance, and analyzes the results when many users access the application at the same time.
You can download the latest version of JMeter from here: http://jmeter.apache.org/download_jmeter.cgi
Once downloaded and installed, we need to open it using the batch file shown in the image below. Double click on the batch file.
After launching the batch file, the screen will look like the below image with two default main components
- Test Plan
- Test Plan – a container of elements used to test performance of any system.
- WorkBench – is a working area which cannot be saved. It includes non-test elements like HTTP mirror server, HTTP(S) Test Script Recorder, and etc.
In this section, we are going to consider the “mstsolutions.com” web application to test the HTTP load on the web server. To begin with, we need to create a HTTP test plan. The test plan includes the following:
- Creation of Thread Group
- Adding the HTTP Request default
- Adding Listeners to View Results.
- Running the Test Plan
Creating the Thread Group:
Thread Group is nothing but a set of virtual users with whom we are going to perform the testing virtually. This will define the number of requests that is sent to the server. We can add this using Test Plan [Symbol] Add [Symbol] Threads [Symbol] Thread Group. This is a required element in JMeter. Once we have added this, a new screen will open and look like below.
- Name: You can change any name of Thread Group by changing the text in Name text
- Action to be taken after a Sampler error: You can control the thread when an error is thrown, by selecting the radio button value.
- Thread Properties: You can define the number of virtual users.
- Ramp-Up period: It is the time taken to send all thread request. Suppose you have configured properties as 10 users, and you define Ramp-Up time as 10, then each request will be sent after 1 second. So all the request will be sent in 10 seconds.
- Loop Count: You can also create a loop of request by defining Loop count.
HTTP Request Defaults:
To avoid the repetitive task of defining the URL for every HTTP Sampler, we can use the HTTP Request Defaults element. This processes HTTP requests by default.
You can add this element by right clicking on Thread Group → Add → Config Element → HTTP Request Defaults
Once our test plan is set up, then we need a component to view our results, once we start executing the script. So we go for the listeners and the listeners have various report types. JMeter provides different types of Listeners and formats we need.
To add Listeners to your test plan, right click on Thread Group → Add → Listener.
Executing Test Plan and Result Analysis:
After the test plan is ready, we need to click the ‘Start’ button from Tool bar or press Ctrl+R to run our test plan. While our test plan is running we can see ‘Green’ indication at top right corner. And when test plan complete, this indicator will turn into Silver color.
We can analyze the test results from View Result Tree which I have shown in below snapshot. We can see the result of Home Page request in Response Data tab. By default, it is text response, but we can also change it to HTML (download resources).
So using Apache- Jmeter, we will be able to perform load testing, and store the results easily. Also, we will be able to view the results in various formats which will help us in analyzing the values easily. Besides, this is an open-source tool that most of us can productively use for our day-to-day testing efficiently.