Table of Contents
JMeter API Testing
In this article on JMeter API testing, we will be discussing the details on API’s, different tools that is used for API testing and also on how to develop an API script for testing using JMeter tool. But before discussing about JMeter API testing, mentioning few details about API’s and tools available to do an API testing.
What is API?
Application Program Interface (API) is a communication layer between different components in a multi-tier application architecture. API’s plays a key role in ensuring an effective communication between different components. Let us try to understand APIs with an example of an ecommerce website. Let’s assume there is an ecommerce website and multiple customers purchases products from this website. Here let us assume that API 1 is a product price related Api and API 2 is product quantity related Api.
Now while customers trying to purchase a product(s), they get information related to price and quantity related to the products on the website is because these Api’s are always interacting with the database to fetch this information and providing it to the customer through the website interface on a real time basis. In this example we have mentioned only two Api’s but in a real-world scenario many API’s will be interacting with multiple components throughout the day.
What is API Testing?
API Testing is a testing practice performed to validate the Api’s are working well in terms of its functionality,performance,security and reliability. It plays an important part of testing life cycle specially during integration testing.
API Testing Tools
Many tools are available in the market to do API testing. Few of the tools are free tools which can be used to test your Api’s. Few of the widely used tools to do API testing is mentioned below.
- SoapUI
- Postman
- Apache JMeter
- Katalon Studio
- Apigee
JMeter API Testing
As mentioned earlier in this article API testing is important to validate an API’s functionality, performance, security and reliability. Hence it is again very important to focus on API’s performance because high performing or faster APIs are always needed to make faster communication between the software components. JMeter API testing can be useful particularly while we test API to understand the performance of it.
Download and install JMeter reading this article JMeter Installation – My Blog (vprad.com)
Below mentioned is a step-by-step approach in developing a JMeter script as part of your JMeter API testing. For creating a JMeter api script making use of some API’s available in Reqres website.
JMeter API Testing – Step1 -Setup JMeter Test plan
To begin with launch JMeter and add below mentioned JMeter components.
- Right click on Test plan and select threads<<>>Thread groups
- Right click on Thread groups and then select add sampler<<>>HTTP Request
- Right click on Thread groups and then select add Listener<<>>View Result trees
- Right click on Thread groups and then select add Listener<<>>Aggregate reports
Once the above listed JMeter components are added your JMeter screen will look similar to below mentioned screenshot.
JMeter API Testing – Step2 -Setup JMeter HTTP Request
Click on HTTP request and will select an api request details from Reqres website. In this example using a Create User request API having a POST method. Ideally an api request will have a request URL, request body, request header and a method. The api used here have a request URL, request body and a method.
In this example request details is as follows.
Request URL is https://reqres.in/api/users
Request body is
{ "name": "morpheus", "job": "leader" } Request method is POST
Now in the HTTP request add the details of the request as mentioned below .
- HTTP Request Name – Give any suitable meaningful name of your choice
- Protocol – HTTP or HTTP(s), In this example it is https:
- Server name – domain name, In this example it is reqres.in
- Method – Select the API method, In this example it is POST
- Path – Add the subdomain, In this example it is /api/users
- Request Body – Add the request body, In this example it is { “name”: “morpheus”, “job”: “leader” }
Note – Incase if your API request have a request header then you need to make sure to add the request header along with your http request. For adding it, right click HTTP Request, select Add config element <<>> HTTP Header Manager.
JMeter API Testing – Step3 -Run HTTP Request and Validate Response.
Now the JMeter API script is ready to be executed. Execute the script clicking on start button (green play button) in the JMeter icons. Validate your response by clicking View results Tree. The performance summary report of API test execution is available in the Aggregate Report (Ref screenshot below)
0 Comments