7 Interesting Postman features for testing
Postman is a tool that helps you to create, document, and test your API requests with Javascript. Postman includes the following features:
1. Test different types of requests
HTTP (REST API) is one of the most popular architectural styles for building API that includes 4 main methods:
GET: To get data
POST: To insert new data
PUT: To update data
DELETE: To delete data
SOAP: It’s a protocol used to interchange info, mostly with XML.
GraphQL: (Beta) Developed by Facebook, it is a query language that returns more specific data with REST API with a query language.
gRPC: Developed by Google, it is an open-source remote procedure call (RPC) framework that enables high performance for client and server applications and is mainly used in microservices.
WebSocket: (Beta) real-time communication between client and server using a persistent communication channel.
Socket.IO: (Beta) Socket.IO is a framework built on WebSocket that enables low-latency, bidirectional, and event-based communication between a client and a server.
MQTT: (Beta) Is a lightweight protocol message primarily used in the Internet of Things
The most basic test to check one of the attributes in the response body is:
pm.test("Test Description", function() {
//Convert response to an object
var response = pm.response.json();
pm.expect(response.value).to.equal("expected value")
});
Some tips for testing API are:
Test all business rules and correct status responses. For example, if your website includes different roles, you can add tests for each.
Test default values: If one API returns results on a page with some default values, like 20 results per page, check the API with a PageSize of 30 and without a PageSize parameter and check that it returns 20 results.
Test with incorrect data and check for a clear error message, mainly if third-party companies use the API. For example:
Don’t send a required parameter.
Test the limits, such as if the page size is a maximum of 50 tests with 51.
For POST methods that insert some data, add a post that inserts duplicated data.
Security test:
Test that you get 401 for API that requires authenticated users.
If some role restricts some info, test with a role without permission and check the status code 403.
Check response time: If the API should return results in a maximum of 2 seconds, add a test that validates that the response time is below 2 seconds.
pm.test("Response time is less than 200ms", function () { pm.expect(pm.response.responseTime).to.be.below(200); });
You can add documentation for your APIs. You can check the Brevo documentation.
With Postman 11, you can use packages to reuse some common functions for different collections.
You can add the Postman extension in VS Code to write your test inside VS Code.
You can learn more about Postman with the playlist
You can check some challenges and win a badge. One for testers is 15 days of Postman for testers!
You can check my Postman collection with some samples
2. Visualize your API data into Charts, Graphs, Maps
You can change the info returned by your API into charts, graphs, HTML tables, and maps. Sometimes, it is easier to check the data in a table or chart than in JSON.
To visualize the data, you need:
Create the HTML code to display charts and set up the chart.js code to display charts. This sample is for testing on my demo site, an Accounts Receivable dashboard.
var template = ` <canvas id="myChart" height="80"></canvas> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script> <script> var ctx = document.getElementById('myChart'); pm.getData(function (err, value) { var myChart = new Chart(ctx, { type: 'bar', // Changed chart type to bar data: { labels: value.response.map(item => item.Cliente), // Used map to extract 'Cliente' values datasets: [{ label: [], backgroundColor: ["#003f5c", "#58508d", "#bc5090", "#ff6361", "#ffa600"], borderWidth: 1, data: value.response.map(item => item.Total) // Used map to extract 'Total' values }] }, options: { legend: { display: false }, title: { display: true, text: 'Top 5 Total' }, scales: { yAxes: [{ ticks: { beginAtZero: true } }] } } }); }); </script>`;
Use the pm.visualizer to visualize the data.
pm.visualizer.set(template,{
// Pass the response body parsed as JSON as `data`
response: pm.response.json()
});
3. Create flows
You can create flows to test the workflows of your web app.
For example, my demo site has two microservices:
Authorization in blue
Dashboard in green
This flow explains the flow
Calls the Login
Calls the menu:
To get the menu options for the user
Check the menu access for the dashboard
Calls the API for the account receivable
Top5Total
Top5Atraso
Top5Tipo
You can learn more about Postman flow in the following video
4. Monitor your collection
You can set up a monitor to execute your API and get alerts by mail for any error. For example, you can set up to execute your collections each hour. With the paid version, you can choose a region, with the free version defaulting to the US (East). You will receive an email if the collections return an error. If you run your collections each hour, you can get notified of the bugs before your users because sometimes users don’t report bugs, only abandon the website. Free versions include 1,000 requests by month.
In this sample, I stopped one of the microservices to get some email with the error.
5. Schedule your collection
You can schedule your collection to run all days, for example, at 7:00 a.m. This can help managers check the status of the daily regression tests.
6. Performance testing
Although there are tools specific to performance, like Jmeter, K6, Artillery, or Gatling, Postman offers load performance testing. The free plan includes 100 virtual users and 25 local test runs. You can simulate users calling the API. In this sample, call the API for 15 users for 1:20 minutes, increase to 30 for the next 1:10 minutes, and hold for 2:30 minutes.
7. Automate your tests with Postbot
Postman includes a Postbot assistant that can help you:
To generate the documentation of your requests
Create test cases for your API
Visualize the request as a table, chart, or bar chart.
Ask any doubt
Debug requests
You can suggest some topics and ask any doubt. Feel free to share the article and enjoy testing.