Two simple tests you should be using with Postman
Tags: testing, automation, rest, webdev
Published: 2019-04-12 14:02:21

---
title: Two simple tests you should be using with Postman
published: true
description: Use these basic built-in tests to make sure you're getting the most from Postman
tags: Testing, Automation, REST, WebDev
cover_image: https://thepracticaldev.s3.amazonaws.com/i/5ac5elzquv9xqnz7qozx.jpg
---

##  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](https://thepracticaldev.s3.amazonaws.com/i/lzjx9hsbyjkomj30g2my.PNG)

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](https://thepracticaldev.s3.amazonaws.com/i/wen5jyq7xet8gq0m9rbg.PNG)

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](https://thepracticaldev.s3.amazonaws.com/i/fcde2haptwv01v46u44i.PNG)

## 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](http.cat) or [HTTP Status Dogs](https://httpstatusdogs.com)

![HTTP Cats 200 OK Status](https://http.cat/200)

> 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](https://thepracticaldev.s3.amazonaws.com/i/ff1xia7aftceu1al8khv.jpg)

> 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](https://twitter.com/ambertests) on the [Test Automation University](https://testautomationu.applitools.com): [Exploring Service APIs through Test Automation](https://testautomationu.applitools.com/exploring-service-apis-through-test-automation/).