Skip to content

Can I Do Performance Testing Using Postman

API Testing Blog

Can Postman Be Used for Performance Testing?

Yes, while Postman is primarily a tool for API testing and development, it can be used for basic performance testing to a certain extent. It offers the ability to send repeated requests and analyze the response times, which can provide insights into the performance of your API.

Postman’s Limitations for Performance Testing

It’s important to understand that Postman is not a full-fledged performance testing tool. It lacks features like sophisticated load generation, distributed testing, and comprehensive performance metrics reporting. For comprehensive performance testing, dedicated tools like JMeter, LoadRunner, or Gatling are ideal.

How to Perform Basic Performance Testing with Postman

Let’s explore how to perform basic performance testing using Postman:

1. Creating a Collection for Performance Testing

Start by creating a Postman collection dedicated to your performance tests. A collection can hold multiple requests, allowing you to test different API endpoints or scenarios.

Sample Code - Create a collection and add a new request:

[
{
"info": {
"_postman_id": "44347369-88ea-4bdc-8543-3c4754a71af0",
"name": "Performance Testing",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "GET User",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.example.com/users/1",
"protocol": "https",
"host": [
"api",
"example",
"com"
],
"path": [
"users",
"1"
]
}
},
"response": []
}
]
}
]

2. Setting Up the Request

Configure your request in Postman. Ensure you specify the correct HTTP method, endpoint URL, headers, and request body. For performance testing, you might need to add a few key elements:

a. Pre-request Scripts:

  • Use pre-request scripts to set up variables, data, or perform actions before sending the request. This can be helpful for dynamically generating data or configuring the request based on your test scenario.

Sample Code - Pre-request script to create a random number:

pm.globals.set("randomNumber", Math.floor(Math.random() * 100));

b. Assertions:

  • Define assertions to verify the expected response status code, response time, or data content.

Sample Code - Assert response time is less than 500ms:

var responseTime = pm.response.responseTime;
pm.test("Response time is less than 500ms", function() {
pm.expect(responseTime).to.be.below(500);
});

c. Global Variables:

  • Use global variables to store data that can be used across multiple requests in your collection.

Sample Code - Creating a global variable to store the API base URL:

pm.globals.set("apiUrl", "https://api.example.com");

3. Sending Multiple Requests

You can send multiple requests manually or use the Runner feature. The Runner allows you to execute a collection of requests repeatedly, which helps in testing the API’s performance under load.

a. Manual Execution:

  • Simply send the request multiple times by clicking the “Send” button.

b. Using Postman Runner:

  • Go to the Runner tab in Postman.
  • Select your collection and specify the number of iterations (the number of times you want to execute the collection).
  • Configure your settings, including the number of concurrent requests, delay between requests, and other options.

Sample Code (Runner):

{
"count": 10, // Number of iterations
"delay": 0, // Delay between requests (in milliseconds)
"environment": {
"id": "YOUR_ENVIRONMENT_ID", // Replace with your environment ID
}
}

4. Analyzing the Results

After running your tests, you can analyze the results in Postman. The Results tab shows the details of each request, including the response time, status code, and any errors.

Key Metrics:

  • Response Time: Analyze the response time for each request. Consider the average response time, the slowest responses, and the distribution over time.
  • Error Rate: Identify any errors that occurred during the test. This helps in understanding potential bottlenecks or issues.
  • Throughput: Calculate the average number of requests processed per second.

Using Postman for Basic Load Testing

While Postman is not designed for full-fledged load testing, you can use it to simulate basic load by sending multiple concurrent requests using the Runner feature. This allows you to get a preliminary idea of how your API performs under load.

Steps:

  1. Configure your request with appropriate assertions and pre-request scripts.
  2. Go to the Runner tab and select the collection.
  3. Increase the “Concurrency” setting to simulate a higher number of concurrent users.
  4. Execute your collection.
  5. Use the results to analyze the performance under load.

Example:

  • Use the “Concurrency” setting in the Runner to simulate 10 concurrent users making requests.
  • Run the collection and observe the response times and error rates.

Conclusion

Postman can be used for basic performance testing, but it lacks the advanced features of dedicated performance testing tools. For comprehensive performance testing, consider using tools like JMeter, LoadRunner, or Gatling. However, Postman provides a valuable starting point for quickly assessing your API’s performance before embarking on more in-depth testing.

API Testing Blog