Using Postman for Integration Tests

Published on Tuesday, December 11, 2018

In my recent project, I'm providing some integration services (APIs) that are used by the web application to fetch data from source systems. This is a legacy project that I inherited. To be honest, this was a PoC and we all know how PoCs are developed and very often continue to be used in production. That is why I have been rewriting/refactoring this codebase (I even tweeted about this a while ago) in every sprint to improve the code quality and cleaning up a lot of code. Since I don't have a proper code coverage for all the source code, I'm always concerned when I'm continuously developing and refactoring this codebase. I'm often concerned (rightfully so) that I'll break my API and will eventually bring down the system due to some stupid mistake.  But until I can have a good enough code coverage I want to be confident that I'm not breaking my APIs whenever I'm pushing a new release to production. Now I've taken quite a lot of steps over past few months (from having proper CI/CD pipeline to having slots support to have the availability for new releases etc) to clean up the codebase and continue to have my services up-and-running, one thing I'm particularly excited about is Postman.

If you are involved in RESTful API development, chances are you are already aware of Postman or atleast have heard of it. But in case this is the first time you heard about the tool, I'll give you a very quick intro about it. 

"Postman mkes API Development Simple" Postman website

Postman is a powerful HTTP client for testing web services. It makes API development faster, easier and better. You can read more about it on their official website

I've been using postman during my development (testing APIs etc) but for last few weeks, I've started to write integration tests for my APIs so that whenever I'm making any changes or creating a new release (for any environment), I can quickly run the collection and make sure everything is still functioning as expected. 

This is not a replacement for having a proper unit test (with good enough code coverage) but I find it very useful to quickly verify that I haven't broken the core functionality of my solution. 

Here are some features I'm using with Postman for my integration tests

  • Test automation
    • Collections
      • One big collection to run tests for all services in one go
    • Separate collections for each service (API) with calls of each operation that API exposes/supports
    • Extended tests to cover different scenarios
  • Debugging
    •  Pre-script and tests for individual calls
  • Environment variables - to have the possibility to test the APIs towards any environment that I want to test 

Even though I've used quite a few features so far but it doesn't end here. Here is what I have planned to take advantage of other features as I go along. 

  • Integrating postman in my CI/CD (newman) so that I can auto swap my slots for the web application if everything is green
  • Mocking
  • Continue to extend my tests cases to increase coverage

How are you using Postman in your projects? Have you found anything intersting/useful that you would like to share?


comments powered by Disqus