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", () => {
    pm.expect(pm.response.json().id).to.equal(pm.variables.get("card_id"))
    pm.expect(pm.response.json().name).to.not.be.empty;
    pm.expect(pm.response.json().idLabels).to.be.an('array')
});

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

5/5

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

equivalence and boundary value

Understanding Equivalence Partitioning and Boundary Value Analysis in Software Testing

Software testing techniques help ensure software quality and reliability, by helping us select test cases intelligently from the collection of test cases, such that all test scenarios are covered.

Boundary Value Analysis and Equivalence Partitioning are two testing techniques that help testers select a subset of test cases that covers all important test scenarios, even under time and budget constraints. By testing all the equivalence classes and boundary values, testers can reduce the risk of releasing software with defects.

Read More »