Postman Load Test Tutorial

In this load test tutorial, you’ll learn how to use Postman for small-scale API testing. You’ll also learn about some shortcomings and challenges of the framework that can be solved by using a tool like Speedscale.

Because HTTP services don’t have a graphical user interface, you’re forced to test web APIs by simulating requests from a known client so that you can control the traffic data. However, if you develop a client application with a graphical interface for testing, you’d be wasting time and resources that could be used in the development of the service itself.

Postman is an application that helps you perform HTTP/S requests from a simple and intuitive interface, facilitating the testing and debugging of REST services. Postman is available for macOS, Windows, and Linux operating systems, and it offers a range of features, including creating and testing APIs.

What Is Postman API Testing

Postman is a tool that aims to test RESTful services (web APIs) by sending HTTP/S requests and analyzing their return. These services can be built with .NET, PHP, Node.js, or any other language.

With Postman, it’s possible to easily consume local and internet services, and do load and performance tests on the responses to request cookies, status code, response time, and so on.

As the use of web APIs continues to grow, Postman will continue to gain traction as it helps developers analyze the functioning of external services so that you know how to consume them.

Below are some of the ways you can use Postman for API testing:

Make POST, PUT, PATCH, and DELETE Requests

When you’re developing a server, you need to test its functionality early in the development process. Postman makes this possible by letting you make requests via its interface to avoid having to depend on frontend development to test the behaviors of your server.

As your API gets more complex, you’re going to have cases that require multiple calls. Thanks to Postman and its Collection Runner, you can launch your calls sequentially and use the answer from previous calls in later ones, all without having to copy and paste the data. Postman also lets you manage environments that allow variables to be contextualized and queries (or series of queries) to be executed in different configurations, typically Dev (development), SIT (System Integration Testing), and Prod (production).

Load Test an API

Load testing is used to test how an API behaves under constant load. For the load test to work, you need to run all the tests at once to create a significant load.

Postman’s Collection Runner can be used to load test an API by specifying a large number of iterations and running a number of such collections in parallel to create a high throughput.

Perform Automated Tests

In the development of any API, unit and integration tests (ie functional tests) are essential for functionality and non-regression. For this reason, Postman offers a testing function that includes functional tests (which are included in the codebase) and the ability to do a mock call to an external API.

When you develop your backend, your tests must cover your logic. For instance, if you’re calling the Twitter API, you won’t actually be making calls to that service every time you do integration testing; instead, you’ll be mocking those calls. If for some reason the Twitter API is unavailable, you don’t want to break your continuous integration (CI) pipeline and work on a bug fix that is beyond your control. That’s why you must do mock calls to external APIs in your automated tests.

However, with Postman, you can have a test suite that calls all your external services. This layer comes in addition to integration tests and can be launched regularly to ensure that when you connect to your real services, everything is still functioning as expected.

Integrate into a CI/CD Pipeline

Postman is compatible with the Newman library and lets you launch the test suite directly from the command line and integrate it into a DevOps CI pipeline.

Using Postman

API testing with Postman lets you test the API both internally and with third-party APIs in several ways, including send requests, test requests, and automated testing. In this tutorial, you’ll use the free RandomUser API, where each GET to the URL https://randomuser.me/api returns a user file in JSON format.

Send Request

To begin sending a request, you need to define a test environment in order to use certain variables in your requests.

After defining the test environment with an environment variable domainname and a value of randomuser.me (the variable and its value depend on the API you’re testing), you can send your configured GET request. In this tutorial, you’re going to pull random details of American women from the RandomUser API:

Randomly generated details of American women

Postman also gives you the option to modify the header of the request to specify the type of identification (Basic, Digest, OAuth, etc.) and to execute JavaScript before each request:

Modify the header

Test Request

Setting up a series of tests to validate the result of queries is done in a similar way. For example, check the following specifications:

var data = JSON.parse(responseBody);
var user = data.results[0];
tests["A single user was returned"] = data.results.length ===1;

// Gender Tests
tests["Gender is female"] = user.gender ==="female"; 

// Nationality Tests
tests["The user is from the United States"] = user.nat === "US";

The Test Results tab of the response to the previous request makes it possible to verify whether both tests were passed:

Testing API in Postman

Automate Testing

When you have a large number of APIs, manually launching each API test becomes time-consuming and error-prone. However, Postman offers a number of ways to automate these tests.

Below, you’ll use the Collection Runner to run queries grouped together as a collection.

The Collection Runner also gives you an option to conduct a series of tests based on a data set. To do this, you have to define a new query with parameters by selecting the data file containing the test variables.

Then you need to run it:

Running the data file postman

You can also use the Postman Monitors feature to automate API testing. A monitor allows a collection to be run at regular intervals to ensure that it remains functional. If something goes wrong, Postman sends you an email notification.

The Postman API Monitors feature is available in the Premium version, but Postman lets you make up to 1,000 API calls per month with its free version.

If you’re using the Postman API Monitors feature, you can follow the behavior of a collection through successive calls. Once the collection has been defined, along with frequency and environment, the results are viewable in a browser after the accepted time-out between the requests. You are notified of each request of the collection, as well as the response times. Here’s a sample monitoring summary:

Summary of monitoring postman

If you increase the number of iterations significantly, you can also use this process to load test an API.

Use a Mock Server with Postman

Postman’s Mock Servers feature simulates your API by recording responses from a real API and outputting them when you call the mock server. This feature is particularly useful when you want to use third-party APIs that charge or limit based on the number of calls made.

Below is an example of a random response:

Mr. Morris Grant random user data

This time, it returned Mr. Morris Grant’s data. You can record this response and, later, use it as an auto-response when you need to call the mock service again.

You can create a mock server by indicating the collection and the environment:

Create a mock server

Once you’ve finished creating a mock server, you’ll now have a URL imitating the behavior of the API:

Mock server URL that will imitate the example

Each request to this URL will return the results used to generate the server; in this case, Mr. Morris Grant’s data:

Response from the mock server

Generate API Documentation

When saving collections and queries, it’s possible to include descriptive comments, which are helpful when working with a team. The documentation feature generates online API documentation, methods, parameters, and supporting multi-language code examples. Here’s what the Documentation option looks like:

Postman load test

Limitations of Postman

Although Postman is a well-packaged tool for manual testing, it has a number of limitations:

  • Postman doesn’t natively support true load testing because it waits to check the response time. This means that there isn’t enough load or stress because the requests are being sent as isolated instances.
  • Postman has limited test automation support without writing assertions in JavaScript, which makes it really hard to guarantee performance stability. In addition, its reporting feature is limited.
  • Postman requires you to manually program and manage mocks, which is difficult for those not familiar with writing scripts and can be time-consuming.
  • Postman does provide support for CI/CD integrations with Newman, but it’s still quite inadequate and limited. Similarly, Postman doesn’t have extensive Google Remote Procedure Call (gRPC) and has only started supporting it recently.

How You Can Mitigate These Limitations

Speedscale can help you with some of these limitations because, with Speedscale, you can stress test your APIs with real-world scenarios.

Mocks generally need to be constantly updated (or they become out-of-date as the API changes), and there’s work associated with keeping mocks up-to-date. In this case, Speedscale can auto-generate mocks that represent third-party dependencies in seconds, based on real traffic.

When you make a change in your API, Speedscale can also ensure the following:

  • You won’t add undue latency as a result of your change.
  • You won’t break your data contracts.

Speedscale automatically generates assertions to compare previously collected traffic against your new updated changes and can help bring the differences to your attention.

Conclusion

Postman is a tool that provides you with a graphical interface to easily manipulate your API. It comes with a number of free and paid features, like the ability to create a mock server, automate testing, and enable monitoring. However, it lacks accessibility and a number of important features, like native CI/CD support and proper load testing.

Speedscale is a complete traffic replay framework for API testing, with native Kubernetes and CI/CD support. It prepares your APIs for real-world scenarios without you having to prepare scripts, using stress testing, auto-generated test, traffic replay, and turnkey chaos testing.

Get started today

Free for 30 days. No credit card required.

    About The Author