Article
· Jun 29, 2023 2m read

How to Create Newman Tests in Postman

Hello Community!

I'm going to try to explain how to create test for Postman collections for use it with my app IRIS Api Tester.

 

Yet, What is Newman?:

Newman is a command-line tool that allows you to run Postman collections in an automated and scalable way. By creating tests in Newman, you can ensure the reliability and correctness of your API endpoints. In this article, we will explore how to create tests for Newman in Postman, along with practical examples to help you get started.

 

Once you have created your Postman Collection:

You're ready to start writing your test scripts:

Tests in Postman are written in JavaScript using the Postman scripting sandbox. To create a test script, open a request and navigate to the "Tests" tab. Here, you can write custom JavaScript code to validate the API response and verify its correctness.

Example 1: Checking the response status code:

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

 

Example 2: Verifying the presence of a specific field in the response:

pm.test("Response body contains name field", function () {
    pm.response.to.have.jsonBody('name');
});

 

Example 3: Checking the response time:

pm.test("Response time is less than 500ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(500);
});

 

Once you have created the tests in Postman, you're ready to export your collection an follow the steps of my this tutorial. 

Or you can watch this video on YouTube: 

https://www.youtube.com/embed/6JJJ0a6dSmY
[This is an embedded link, but you cannot view embedded content directly on the site because you have declined the cookies necessary to access it. To view embedded content, you would need to accept all cookies in your Cookies Settings]

 

Thanks for reading!!

Discussion (0)1
Log in or sign up to continue