Performance Testing of RESTful APIs Using JMeter

What is a RESTful API?

REST (Representational State Transfer) is a simple stateless architecture that uses HTTP protocol. In a Client-Server Application most of the web services use REST API so that clients, third party applications can access its resources using URI (Uniform Resource Identifier)
How do we do the Performance testing of RESTful API’s?



Like for any testing process, the testing team needs to create a test plan.We need a proper  set of benchmark numbers (SLA) for response time, throughput and CPU Memory usage before starting the Performance tests . If we don’t have this then  industry standard benchmark numbers cam be taken into consideration.
Let’s create a JMeter test Plan as below.


  • Add Test Plan, Thread Group, HTTP Header Manager, HTTP Request Defaults, Sampler HTTP Request for REST

  • Add CVS Data Set Config

  • Add Response Assertion

  • Add Listener (View Result Tree, Aggregated Report)

  • jp@gc-Response Times over Time

  • Run the Test Plan

  • View Output


In the steps given below we can understand how to configure and use JMeter for Performance testing of RESTful API under test.

1. Add “Test Plan” element.

Initially create the Test plan as depicted  below. Click on the Test Plan node. Rename this Test Plan node as REST API Performance Test.

Picture2

2.  Add “Thread Group” element.
We can configure the load test using this element where we simulate the concurrent virtual users as well as the time duration for the load test. Users need to configure “Thread Group” as per their setup.

Picture3

3. Add “HTTP Header Manager” Config element.
The “HTTP Header Manager” decides the HTTP header content in the requests and used to add or override HTTP request headers. You need to add Content-Type for REST API as below.
accept: */*
Content-Type: application/json;charset=UTF-8
4.  Add “HTTP Request Defaults” Config element.
You need to configure the Domain name or IP address of the web server. e.g. www.abc.com. [Do not include the http:// prefix. under “Server Name or IP”
5.  Add “HTTP Request” Sampler element.
Now that we have defined our users, it is time to define the tasks that they will be performing. We will add HTTP Request element. Click your right mouse button to get the Add menu, and then select Add > Sampler > HTTP Request.
Configure REST API “Path” and JSON Request in “Body Data” as well as “Method” as given below.
Here “Path” is nothing but the URI which identifies the REST API under test.

Picture4

Note: Configure “Path”, “Method” and “Body Data” as per your REST API under test.
6.  Add “CSV Data Set Config” Config element.
JMeter uses CSV test data dynamically at run time there are various advantages to use CSV data as below.

  • We can store multiple data objects/variables for  a profuse number of iterations using a single file.

  • Multiple scripts can use this CSV data for numerous  loops.

  • We can directly change the CSV file to update the data values, without the need to update the .jmx file. Please configure the CSV data as below.


Picture5

7.  Add “Response Assertion” element
To verify the REST API Response has proper Response data
8.  Add “View Result Tree” and “Aggregated Report” Listener element.
The final element you need to add to your Test Plan is a Listener. This element is responsible for storing all of the results of your HTTP requests in a file and presenting a visual model of the data.After running the load for configured time duration analyze the test results using aggregated report.

9.  Add “jp@gc-Response Times over Time” Listener element.
The following graph shows response time during the load duration for the specific REST API under test.

Picture6

10. Run the  test plan and  view output in the listener
From this blog we see a detailed view of how JMeter can be used for Performance testing of RESTful API’s.

More information here

Comments

Popular posts from this blog

Robot Framework vs Cucumber

Verification displayed number of rows inside table by Robot Framework