6 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

You are here

Postman for API Testing

Postman is a great tool for prototyping APIs, and it also has some powerful testing features. Mike shares how to integrate Postman's tests into your build automation to make things really take off.

I've used Postman on a few projects as a way to interact with APIs that I'm writing. As a tool to setup complex HTTP requests, it's much more convenient than request specs, Cucumber, or hand-rolling them in even your favorite HTTP library. One admittedly huge advantage these other methods have had for me in the past is the ability to integrate them with my regular testing tools—but no more. The people behind Postman have released a command-line tool for running Postman collections called Newman. Let's take a look at how to use Newman to get more out of Postman.

Postman is a Google Chrome app for interacting with HTTP APIs. It presents you with a friendly GUI for constructing requests and reading responses. The people behind Postman also offer an add-on package called Jetpacks, which includes some automation tools and, most crucially, a Javascript testing library. This post will walk you through an example that uses those testing features. While they won't replace your focused unit tests, they do breathe new life into testing features from outside your applications. This makes it extremely valuable for functional testers or for developers who love to test outside-in.

If you already have Jetpacks, you can follow the example here—be sure to click the import tab in Postman and use the Download from link tab to import the collection.

 

Get Started

Google's URL shortener expects a single parameter enclosed in a JSON document. Let's construct a request and make sure Google's response actually gives us a short URL. This is what Postman should look like once that has been set up.

Postman pretty-prints the response, and it looks like Google's API is working.

I don't want to look at the response every time I make a request, so I'm going to have Postman look at the response to make sure it has the element we want in it. Clicking the "Tests" button off to the right of "Send" opens a text box where we can write some javascript. Postman builds a collection called tests that takes a description and a boolean value, which it will display for us. Then you can pass it a description and set its value by making an assertion about some aspect of the response. In this case, we assert that the API must include an id element in the response.

If this were our own API, we would go further and make similar assertions about HTTP status codes and the expected failure responses our API generates. Not pictured in these examples are Postman's examples to the right of your test code. They show you several ways you can measure how your API behaves and performs.

 

Running Newman

This is all well and good, but opening Postman is an extra step to your existing tests. If we're honest, that just means that none of this will get used after we've spent so much time on it. This is where Newman comes in. Installation is via npm, but before we can run it, we need a file from Postman. If you downloaded the collection above, this should already appear in the sidebar. If not, add the request you've made yourself to a collection and use the share link to download it as JSON. Save that file with your other project files.

I haven't found a ruby gem that integrates Newman with Rake, but at least until something more sophisticated comes along, Ruby's system command will suffice well enough. Newman is a good Unix citizen, and we can evaluate its return code to determine if there were any errors during execution. This should drop seamlessly into whatever continuous integration tool you use and interrupt builds just like any other test failure.

With Newman, you can integrate Postman collections with your build system. Or you can run automated tests for your API through a cron job. You can also use Newman as a grunt plugin to run your API tests any time you save your code in your editor. There are tons of other ways to use Newman and we can't wait for you to try it out!

The setup involved is absolutely minimal. You can check out the Newman repository on Github: https://github.com/a85/Newman for more details. The code is licensed under the Apache license. Your contributions are welcome!

This has been one of the top feature requests since the release of Jetpacks and we are very excited to show this to you.

 

Read More...check-out reference url

yes

About The Author: 

QATestingTools.com, more technical information on Software Testing Tools and Testing Resources

 

Media: 
Postman

MANUFACTURERS Wallboard

Testing tool manufacturers world-wide list
10Levels ABID CONSULTING AccelQ Accord Software ActiMind AdaCore
AdaLog AgileLoad AgileWay Agitar Algorismi ALL4TEC
Android Apache Apica Apollo Systems AppAssist.mobi Applitools
AppPerfect Appsee ApTest Assertible Assure Atlassian
AutoIt Consulti .. Automation Anyw .. Automation Cons .. Aztaz Software Backtrace I/O Badboy
BlazeMeter Borvid BrowserStack BSQUARE BStriker Intern .. CA Technologies
Canonical Canoo Catch Limited CelestialTeapot Celtic Testing .. Chris Mallett
Cleanscape CloudQA CodeCentrix CodePlex projec .. Codoid Cogitek
Compuware Configure IT Conflair ConSol Core Services Countersoft
CresTech Softwa .. Cross Browser T .. Crosscheck Netw .. Crowdsourced Te .. Cucumber Ltd Cyara
Cygnet Infotech DareBoost Databene Datamatics Glob .. DevExpress DTM soft
Dynatrace LLC EasyQA Eclipse EKA TechServ Elvior Emmanuel Jorge
Empirix EPAM Systems Equafy Esterel eXept Software .. Experitest
Finaris Froglogic FrontEndART Ltd GeneXus GitHub project gnoso
Google Code Pro .. GrammaTech Gurock Software Hewlett Packard .. Hexawise High-Tech Bridg ..
Hiptest Hitex IBM Rational imbus Shanghai Impetus Inflectra
informUp INTALIO intechnica InTENSO - IT Ex .. Ipswitch Jamo Solutions
JANOVA JAR Technologie .. JBoss Developer jClarity Jellly.io JetBrains
Jively jQuery foundati .. JS Foundation Jspresso Kanoah Software KMS Technology
Kualitee LDRA Limited Litmus LoadFocus Loadster Perfor .. MarathonITE
Marketcircle Marketcircle Maveryx Meliora Ltd Micro Focus Sof .. Microsoft
Mobile Labs Mobile1st Mockaroo, LLC ModalLogic IT Monkop Inc Mozila
MSys Technologi .. Navicat NeoTys NetCart Netvantage Tech .. NORIZZK.COM
Novosync Mobili .. NRG Global NTT Resonant OC Systems Odin Technology OpCord
Oracle Orcanos Original Softwa .. Ossia Conseil OW2 PANAYA
Parasoft PassMark Patterson Consu .. Perfecto Mobile Pivotal Labs Plutora
Polarion Postman (API To .. PractiTest PrimaTest Process One Programming Res ..
Psoda PureLoad PushToTest Python Q-Assurance QA Systems
QACube QASymphony QAWorks QMetry Quali QualiTest
Qualitia Softwa .. Quality First S .. Quotium RadView Softwar .. Ranorex RedLine13
Reflective Solu .. ReQtest RevDeBug Robotium Tech Rogue Wave Soft .. Rommana Softwar ..
RTTS ruby-doc.org Runscope Sandklef GNU La .. Sauce Labs Seapine Softwar ..
SeleniumHQ Sencha Sensiple SmartBear Softw .. SmarteSoft SOASTA
SoftLogica Softomotive Softsmith SolutionSoft Sy .. SonarSource Sourceforge
SqashTeam SQS Software Qu .. Square Stimulus Techno .. Swifting AB Synopsys
T-komp T-Plan TechExcel TechTalk Telerik By Prog .. Tellurium
Test Collab Test Goat Test Recon TestCaseLab testCloud.de Gm .. Testenium
Testim.io Testing Technol .. TestingBot TestLodge Testmunk TestObject GmbH
TestOptimal TestPlant TestPro Testuff The Core Bankin .. The MathWorks
The Open Group thePHP.cc Thoughtbot Thoughtworks Tigris.org Time Simulator
Top-Q Trace Technolog .. TrendIC TRICENTIS Tritusa Pty Ltd TWD Solutions P ..
TypeMock Tyto Software Ubertesters UniTESK Universal Test .. Usetrace Ltd
Utrecht Univers .. Validata Group Vanamco AG Vector Software Veracode Verifaya Corpor ..
Verit VersionOne Viewlike.us Vornex Inc. Watir.com WcfStorm Soluti ..
We Are Mammoth Web Performance .. Wikidi Wintask Wireshark Found .. Worksoft
Xceptance XebiaLabs XK72 Xpand IT XQual YesSo
ZAPTEST Zeenyx Software .. Zephyr Zeta Software zutubi pty

Theme by Danetsoft and Danang Probo Sayekti