Performance Testing in Postman

In this latest blog from the developers on our Product Traction team, they outline their best practices for performance testing in Postman.

Performance testing is an essential step in ensuring that your APIs can handle the load and perform efficiently. In this blog post, we will walk you through how to set up and run performance tests in Postman, and share specific insights from our experience, including handling issues related to updating environment variables in post-scripts.

What is Performance Testing?

Performance testing involves evaluating the speed, responsiveness, and stability of a system under a particular workload. In the context of APIs, it means sending multiple requests to see how the system handles them.

Setting Up Postman for Performance Testing

To start performance testing in Postman, you need to:

  1. Install Postman: If you haven't already, download and install Postman.
  2. Create a Collection: Group all the requests you want to test into a collection. This helps in organizing and running them together.

Running Performance Tests

When you run a performance test, you're essentially sending the same queries with multiple virtual users. For example, imagine you have 20 users who send the same queries over time. Postman allows you to simulate this behavior effectively. You can group your test queries in a collection, and select which queries you want to run. Also you can select the type of performance test you want to run. There is 4 options in postman (from the postman documentation): 

  • Fixed: The maximum number of virtual users is used throughout the test.
  • Ramp up: Enter an Initial load and drag the handles to adjust the length of the ramp up period. During the ramp up period, the number of virtual users increases from the initial load to the maximum.
  • Spike: Enter a Base load and drag the handles to adjust the duration of the spike. During the spike, the number of virtual users increases from the base load to the maximum, then decreases back to the base load.
  • Peak: Enter a Base load and drag the handles to adjust the duration of the peak. During the peak, the number of virtual users increases from the base load to the maximum, holds steady, then decreases back to the base load.

Using Pre-Scripts for Dynamic Payloads

If you need to change something in the payload over time, you can use pre-scripts to tweak part of the code and have a variable change. For instance, in our case, we needed a unique document file name for NetSuite testing. We used a pre-script and a variable to get and set the value before each query was sent.

Here's how you can set variables in Postman that can be used before and after each query:

// Pre-request Script

pm.environment.set("fileName", `file_${new Date().getTime()}`);

Setting Environment Variables

You can set environment variables in Postman that can be read and modified during test execution. This is particularly useful when you need to pass dynamic data between requests.

Handling Long API Calls: A Real-World Challenge

One challenge we faced was with NetSuite queries, which were very long (10s per query). This caused problems with changing the values in the post-script because we wanted to run the queries in parallel. The delay in execution meant that updating the value in the post-script wouldn't work as expected. This issue was compounded when multiple queries were running simultaneously, leading to conflicts and incorrect data being used.

Solution: Using Pre-Scripts for Updates

To resolve this, we needed to make the update in the pre-script. Here’s what we did:

  1. Set the Unique Filename in Pre-Script: By setting the file name in the pre-script, we ensured that each request had a unique value before execution.

// Pre-request Script

const index = pm.environment.get("index");

pm.environment.set("fileName", `file_${index}`);

  1. Read the Filename in the Request: Use the variable in your request body or headers.

{

  "fileName": "{{fileName}}"

}

  1. Optional: Increment the Name in Post-Request Script: If needed, you can increment or change the variable in a post-request script, but be cautious of the execution time.

// Post-request Script

let currentName = pm.environment.get("fileName");

let newName = `${currentName}_1`;

pm.environment.set("fileName", newName);

Performance testing in Postman is a powerful way to ensure your APIs can handle the load efficiently. By using pre-scripts and environment variables, you can handle dynamic data and unique values effectively. Remember, if your API calls are long, updating variables in post-scripts might not work as expected, and you should consider updating them in pre-scripts instead.

We hope this guide helps you get started with performance testing in Postman. Happy testing!


The Thin Air Labs Product Traction team provides strategic product, design and development services for companies of all sizes, with a specific focus on team extensions where they seamlessly integrate into an existing team. Whether they are deployed as a team extension or as an independent unit, they always work with a Founder-First Mindset to ensure their clients receive the support they need.

To learn more about our Product Traction service, go here.

Build what's next with us