Postman Load Test: Tutorial & Examples

October 10, 2023
10
min

Founded in 2012, Postman has become widely adopted across the development community. Originally created as a basic HTTP client for Google Chrome, Postman evolved from a simple request/response tool to a robust platform that supports API development, testing, monitoring, and documentation creation and management.

Postman has recently introduced new features within the tool to support API load testing. These features allow developers to run tests on existing API endpoints defined in Postman Collections and configure parameters, such as the number of virtual users, test duration, ramp-up duration, and load profile. Although these features provide helpful load testing functionality for relatively simple use cases, Postman does not yet provide the robust capabilities of a dedicated, purpose-built load testing solution.

In this article, we will explore Postman’s core functionality and provide an example of how to conduct a Postman load test. We also discuss the limitations of Postman load testing that are addressed by modern SaaS platforms like Multiple.

Summary of key Postman concepts

The table below provides a summary of important concepts presented in this article.

Concept Description
Postman’s core functionality Postman allows developers to rapidly prototype and test APIs without writing code. You can define APIs directly within the tool or by importing an existing API definition from a file, folder, or git repository.
Postman load testing More recent Postman features allow developers to simulate user traffic to test API performance in various load scenarios. Tests are run using local computing resources and measure metrics such as response time, error rate, and throughput.
Postman load test parameters Postman supports load testing API endpoints with a configurable number of VUs, test duration, and load profile.
Postman limitations Although helpful in performing a sequence of predefined API calls, Postman lacks features necessary for large-scale or more nuanced load testing, such as:
  • Programmability
  • Ability to create uniquely identifiable VUs
  • Support for a high number of VUs and concurrent requests.
  • Load testing using a SaaS alternative SaaS load testing solutions offer features that address many limitations of Postman load tests, including better programmability, managed test infrastructure, and more comprehensive reports of test results.

    Postman’s core functionality

    Postman's primary functionality revolves around sending API requests and validating responses. Postman Collections allows developers to organize requests into different directories, such as all requests related to a given API.  Postman Environments provide a mechanism for defining variables that apply to a group of requests. For example, a team building a production and a staging environment for their software can employ variables to replicate the same API calls. They can adjust cookies or authentication details or change the base URL between production and staging servers. The feature eliminates the need to rewrite requests for each environment, improving efficiency.

    Postman also provides a mechanism for creating APIs through its API Builder feature. Developers can build APIs via a GUI within the Postman desktop application, either from scratch or using an existing collection as a starting point. Postman also allows developers to create APIs by importing API definition files in formats like OpenAPI, Swagger, Protobuf, GraphQL, and cURL.

    The strength of Postman lies in its versatility; it supports several types of APIs and communication protocols, including REST, GraphQL, gRPC, SOAP, WebSockets, and message queue protocols. Other key features of Postman include tools that allow developers to create API documentation, run automated API tests, monitor API performance, and create mock servers. In the following sections, we will explore features that facilitate load testing using Postman in greater depth.

    Postman load testing

    Load testing involves assessing the behavior of an application under expected load conditions. It helps identify performance bottlenecks and ensures the application handles the expected number of concurrent users without compromising performance.

    Postman has recently introduced functionality to enable developers to conduct API load testing using an existing Postman Collection. The process for setting up tests is relatively simple.

    • Group requests into a Collection.
    • Access Postman’s Runner feature and specify which requests should run and in which order.
    • Configure the number of virtual users, test duration, and load profile before running the test.

    One important consideration for Postman load testing is that Postman generates virtual users locally. Hence, the number of virtual users you can simulate depends on the host machine’s available system resources. Going beyond that number can cause issues with system memory and test accuracy.

    {{banner-1="/design/banners"}}

    Postman load test example

    To better understand Postman load testing capabilities, this section provides a brief tutorial on how to set up load tests using Postman.

    Step 1: Set up the test

    Using the Postman desktop application, choose the Postman Collection you want to load test. If you don't have a Collection, create one with the requests you need to test.

    Click the 'Run' button next to your chosen Collection and choose which requests to test and in which order.

    Postman desktop application

    Ensure you run the tests in the appropriate Postman Environment, then switch to the 'Performance' tab.

    Step 2: Define the load settings

    Under the 'Performance' tab, specify the following load settings:

    Virtual users

    The number of concurrent users you want to simulate. These users will simultaneously send requests to API endpoints to simulate load on the API.

    Test duration

    The duration (in minutes) for which you want to run the test.

    Load profile

    Choose between a 'Fixed' load profile or a 'Ramp up' load profile. A 'Fixed' load profile maintains a constant number of virtual users throughout the test, whereas a 'Ramp up' profile gradually increases the number of virtual users over a specified 'Ramp up duration' before maintaining the peak number for the rest of the test.

    Step 3: Analyze the results

    Once the test begins, Postman begins simulating load on your API, and you can monitor real-time performance metrics. Postman supports four performance metrics:

    • The total number of requests sent
    • Throughput (or requests per second)
    • Response time
    • Error rate
    Graph of metrics generated from a Postman load test

    Postman load test limitations

    As we have seen, Postman offers features to support some load testing use cases. One of the greatest strengths of Postman’s load-testing functionality is its convenience. Developers already using Postman to develop and validate APIs can use this functionality to load test their APIs within minutes for more basic use cases. However, you should consider the limitations of Postman’s load-testing capabilities before choosing it as a primary or exclusive load-testing solution.

    Lacks programmability

    Although Postman allows developers to run a sequence of API calls defined in Postman Collections, it does not allow developers to write actual test scripts with programmatic elements like conditional branching, loops, and error handling. It prevents developers from testing more complex user journeys and using parameterized scripts for dynamic test data, such as data read from different file sources or generated via a library like Faker. As a result, test scenarios become less robust and may not accurately reflect real user behavior.

    Cannot monitor individual test users

    In addition, Postman does not provide a mechanism for identifying and monitoring each virtual user throughout the duration of each test. Besides contributing to issues with programmability described above, this lack of uniquely identifiable virtual users also prevents a more granular analysis of test results that can help pinpoint the source of performance issues.

    It also causes difficulties when working with authentication tokens, such as JWTs. Without the means to identify individual virtual users, Postman is not able to perform login functionality and receive a unique token for each user. This limitation will be explored in greater detail using a code example in the next section.

    Limited scalability

    Finally, the most significant limitation of Postman load testing is that it relies entirely on local computing resources to simulate load. Load generation cannot be distributed across multiple machines, placing a hard limit on scalability. Every virtual user in the test also shares the same IP address–that of the client computer. You cannot simulate traffic from different geographical locations, causing issues when testing system components that expect traffic from different IPs, such as load balancers.

    Load testing using a SaaS alternative

    Next, we explore how you can address Postman load test limitations using modern, purpose-built SaaS load testing solutions.

    A programmatic example of SaaS load testing

    To illustrate some potential programmatic differences between Postman and SaaS load testing solutions, consider the code snippet below:

    const apiClient = axios.create({
      baseURL: ctx.env.BASE_URL,
      withCredentials: true,
    });
    
    
    // attempt to log in as an existing user and get a JWT
    let res = await apiClient.post('auth/signin', {
      email: `user${ctx.info.vuId}@loadtestexample.com`,
      password: 'test#1234',
    })
    
    let jwt = res.data.token
    
    if (!token) {
      // user does not exist in the database and must sign up
      res = await apiClient.post('auth/signup', {
        email: `user${ctx.info.vuId}@loadtestexample.com`,
        password: 'test#1234',
      })
    
      jwt = res.data.token
    }
    
    // print JWT to ensure we have received it correctly
    ctx.log('JWT Token: ', jwt)
    
    // Set the authorization header
    apiClient.defaults.headers.common['Cookie'] = `ACCESS_TOKEN=${jwt}`
    
    // user is now authorized to make API calls
    apiClient.post('resource', {
      message: faker.string.alphanumeric(10),
    })
    

    Sample JavaScript load test script with control flow logic, environment variables, and npm packages

    There are several aspects of this script worth noting. Firstly, like Postman Environments, this script utilizes an environment variable stored under the injected ‘ctx.env’ parameter for the API’s base URL. In addition, the script uses both the Axios and Faker NPM packages to make HTTP requests and generate dummy test data, respectively.

    Utilizing familiar third-party packages within test scripts provides several important advantages. For example, it allows developers to use their preferred ORMs or database clients, and it makes testing services like Websockets, gRPC, Redis, GraphQL, SQL, and OAuth 2.0 much more straightforward. Developers can also write test scripts similarly to client-side code, reducing the time it takes to write tests.

    The example script above also uses control flow logic to decide whether a virtual user can sign in using an existing account or must sign up for a new account to receive a JWT for authentication. During the sign-in and sign-up processes, the script utilizes  each virtual user’s unique ID (stored in ctx.info.vuId) to create or access each virtual user’s unique account. Finally, the script uses the debugging function ctx.log() to inspect and verify the JWT each virtual user receives to access protected API routes.

    Although the example above is relatively straightforward, one can imagine how you can leverage the features of the test script above (environment variables, third-party packages, control flow logic, unique virtual user IDs, and debugging functions) to write complex load testing scenarios quickly and in a way that accurately represents real user behavior.

    Other benefits of SaaS load testing

    Besides greater programmatic flexibility, some SaaS solutions include other features that facilitate more robust and intuitive testing. For example, hosted load testing solutions manage the underlying IT infrastructure to generate load on the test target. This offloads a considerable burden of time and knowledge and allows load tests to scale almost infinitely with little or no effort from development or QA teams.

    In addition, tools like Multiple facilitate greater collaboration by storing test scripts and results centrally. Multiple also can generate more comprehensive test reports by creating custom metrics. It represents these reports graphically and you can also export them to a file.

    Multiple dashboard
    Sample results report from a load test using custom metrics

    Conclusion

    Postman continues to be a powerful tool for API development and testing, and it is widely used across the development community. More recent Postman features allow developers to test API performance using local system resources and track metrics like response time, throughput, and error rate. While Postman’s new capabilities provide a convenient mechanism for running load tests, the platform does not yet include the more comprehensive capabilities of a purpose-built SaaS load testing platform. We hope the information in this article helps inform your team’s decisions on which load testing solutions best fit your use case.

    {{banner-2="/design/banners"}}