avatarEric Anicet

Summary

This context provides a step-by-step guide to API integration testing using Postman, Newman, and Jenkins Pipeline.

Abstract

The context begins with an introduction to the topic of API integration testing using Postman, Newman, and Jenkins Pipeline. It then goes on to explain what each of these tools is, with brief descriptions and quotations from their respective official websites. The prerequisites for following this guide are listed, which include having a GitHub repository, Git, Jenkins instance installed, Node JS, NPM, and Postman. The guide then goes on to explain how to set up a Jenkins pipeline that uses Newman to run a Postman collection, with detailed steps and screenshots. The guide also includes code snippets and instructions for exporting a Postman collection and running it with Newman. The guide concludes with a note about replacing the GitHub repo link with your own in the pipeline script and instructions for running the build test manually.

Bullet points

  • This context provides a guide to API integration testing using Postman, Newman, and Jenkins Pipeline.
  • The guide begins with an introduction to the topic and an explanation of what each of these tools is.
  • The prerequisites for following this guide are listed.
  • The guide explains how to set up a Jenkins pipeline that uses Newman to run a Postman collection.
  • The guide includes detailed steps, screenshots, code snippets, and instructions for exporting a Postman collection and running it with Newman.
  • The guide concludes with instructions for replacing the GitHub repo link with your own in the pipeline script and running the build test manually.

API integration testing using Postman, Newman, and Jenkins Pipeline

In this story, we’ll explain the API integration testing solution step by step using Postman, Newman, and Jenkins pipeline.

This story shows how to set up a Jenkins pipeline that uses Newman to run a Postman collection.

Prerequisites

This is the list of all the prerequisites for following this story:

  • A GitHub repository
  • Git
  • Jenkins instance installed
  • Node JS
  • NPM
  • Postman

Overview

What is Postman?

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs — faster.

What is Newman?

Newman is a command-line collection runner for Postman. It allows you to effortlessly run and test a Postman collection directly from the command line. It is built with extensibility in mind so that you can easily integrate it with your continuous integration servers and build systems.

What is Jenkins?

Jenkins is an open source continuous integration/continuous delivery and deployment (CI/CD) automation software DevOps tool written in the Java programming language. It is used to implement CI/CD workflows, called pipelines.

Getting started

1- Postman collection

Open postman -> File -> New -> Collection

Then, inside the collection, we will create the different requests that we want to test on our API. For this story, we will use the fake “JSONPlaceholder” API endpoints.

JSON-Placeholder Collection

With Postman we can add scripts to each request. Testing confirms that our API is working as expected, integrations between services are working reliably, and changes have not broken existing functionality.

The Pre-Request Script tab will run before our request is sent, and the Tests tab will run after we receive our response.

Tests are scripts written in JavaScript that are executed after a response is received. Tests can be run as part of a single request or run with a collection of requests.

Postman Test Results

In order to run a collection with Newman, we need to export it from Postman

2- Set up Jenkins

  • Install globally newman and newman-reporter-htmlextra packages

npm install -g newman

npm install -g newman-reporter-htmlextra

  • Create a new pipeline project

With Jenkins running, On the Dashboard page, select New Item on the left sidebar to create a new job.

Select Pipeline from the options. Name your project, and select OK.

On the job configuration page, we will add the pipeline script below:

Don’t forget to replace the GitHub repo link with your own in the pipeline script.

  • Select Save to finish creating the job.

Let's run this build test manually by clicking on the “Build Now” link in the sidebar.

Jenkins job Pipeline UI view
Job console output View
Newman HTML Reporter View

All done.

Photo by Eden Constantino on Unsplash

If you enjoyed this article, please give it a few claps for support.

Thanks for reading!

The sample code is available on GitHub.

References

Jenkins
Jenkins Pipeline
Postman
Integration Testing
Newman
Recommended from ReadMedium