loading...
Cover image for Two simple tests you should be using with Postman

Two simple tests you should be using with Postman

dowenb profile image Benjamin Dowen ・2 min read

Add some tests

Postman is a fantastic part of your testing toolbox. I've recently had cause to use it to help track down a performance issue.
One thing I found pretty quickly, is that reading a wall of "PASS" results in the test runner, and trying to pick out slow responses is painful.

So how do you get a bit more out of Postman, without investing time writing detailed tests? Simple, use the built-in examples!

Capture the request you want to test

First you need to capture the request you want to test. If you don't already know what this is, you can capture it pretty easily.

Copy request as cURL Bash from Chrome

Load Dev tools in a browser such as Chrome, visit the page you want to test, identify the network request and right-click copy request (cURL Bash).

Now use the "Import" option in Postman, and import as "Raw text", past in the copied request.
Import request as raw text

Tip: Note if your request is authenticated, this will only work while your bearer token is valid.

Open the "Tests" tab

Open the "Tests" tab on your request, this is where you will see, on the right, a list of built-in examples.
Postman Tests tab

Check HTTP status code

At a very minimum, you should have an idea what return code your expecting. If you expect the request to be successful, your probably looking for "200" OK.

For other HTTP codes see: HTTP Status Cats or HTTP Status Dogs

HTTP Cats 200 OK Status

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

Check Response time

And here is the fun bit, setting an expected response time. This is another built-in example, make good use of it!

Speed

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

Use the Collection Runner to run it lots of times

Now if you want to check running the request many times - save the request to a "Collection" and use the Test Runner to run it lots of times!

For extra danger, try injecting faults or creating a "worse case scenario" while the test is running to see how your service responses to fault conditions.

Learn more

I learned a lot of what I know about Postman from the excellent free course by Amber Race on the Test Automation University: Exploring Service APIs through Test Automation.

Posted on by:

dowenb profile

Benjamin Dowen

@dowenb

I'm a quality hero, customer champion. Experienced software tester and newbie developer. Okay, so I've actually been dabbling in code for a long time. I've just not gone very deep in any language .

Discussion

pic
Editor guide
 

Thanks Benjamin.

I'm diving into this tutorial now learning.getpostman.com/docs/postm...

Hope you got the job soon.