SDET Unicorns

Creating Postman Tests

Postman Tests

Table of Content

In this post, we will be creating Postman Tests and take a look at some of the advantages of using Postman Tests.

Advantages of Postman Tests

  • We can validate the response of the API to ensure it’s working as expected. So far we have just been making API requests using Postman but how do we know the data being returned is what we want, using tests we can verify the response and the functionalities of our APIs.
  • We can perform regression testing to ensure new development changes haven’t broken existing functionality. One of the main purposes of writing these tests is to make sure if something breaks we catch it right away through the automation we have built using these tests without having to do anything manually.

How to create Postman Tests?

We can use the pm.test function to create tests in Postman. Here’s an example where we are verifying the status of the response we got back.

Postman Tests

Postman tests use ChaiJS BDD syntax for test assertions. For those that are not familiar with Chai JS, it’s a JavaScript testing library that allows you to add test assertions. Some examples of that are –

  • .to.have
  • .to.equal
  • .to.not.have

These are quite readable and you easily know what the assertion is trying to verify.

Postman Test to verify response body

In the example below, we created a test to verify the response body by using various Chai assertions –

pm.test("Verify response body", () => {

Check out the video below to learn more about Postman Tests –

To learn about API Test Automation using JavaScript, check out my free tutorial series here –

JavaScript API Test Automation Tutorial Series

I hope this post helped you out, let me know if you have any questions in the comments below!

Happy testing! 

My Resources

Thrive Suite: The all-in-one WordPress theme I used to create my blog.
Jasper AI: My favorite AI writing tool.
Surfer SEO:  A tool to help you rank your content on the first page of Google.

Write Content Faster


Write blog posts that rank for affiliate terms!

Join our mailing list

Unlock the Secrets to Becoming a SDET Pro in the Industry!

Stay ahead of the curve! Join our mailing list for exclusive insights, tips, and the latest industry updates delivered straight to your inbox

Table of Content

Related Post

Functional vs Regression Testing

Functional Testing vs Regression Testing: Main Differences

Testing has increasingly become a requirement in the software development lifecycle in recent years. The realization that development is no longer a focal point for stakeholders but saving costs by catching defects early in their application makes it necessary to learn different testing types.

Read More »