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.
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.
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.
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
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!
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.
Top comments (2)
Thanks Benjamin.
I'm diving into this tutorial now learning.getpostman.com/docs/postm...
Hope you got the job soon.
thanks benjamin for this tests I am creating a complete test suites for my firm and it is really helpful
back to work :)