Automate API Testing with Postman and Newman in a CI/CD Pipeline

August 12, 2025

If you work with APIs, you know this routine all too well. Every time you push a new feature or fix a bug, the nagging worry begins. Did I break something in the login endpoint? Does the user profile still return the correct data? So you open up Postman, load your requests, and manually click “Send” on each one, just to make sure everything is still okay.It’s tedious. This manual grind is exactly why learning how to automate API testing is such a critical skill for modern development teams.

But before we dive into the “how,” let’s be clear: manual testing is, and always will be, absolutely crucial. It’s irreplaceable for exploratory testing, where a developer’s intuition can uncover bugs that no script would ever think to look for. A human tester can think like a real user, questioning if the application flow is intuitive or confusing. They can spot visual glitches, awkward layouts, or typos that an automated script, focused only on data, would completely miss.

The goal of automation isn’t to replace this vital, creative work. Instead, it’s about targeting the other kind of testing: the repetitive, predictable regression checks that are perfect for a machine. By automating these tasks, you free up your skilled engineers to do more of the intelligent, exploratory testing they do best.

What if you could build a safety net? A system that automatically runs all your critical API tests every single time you push new code, giving you instant feedback and the confidence to move fast. This level of automation is achievable, and it’s exactly what you’re going to build today.

In this guide, we’ll walk you through the entire process of transforming your manual Postman tests into a fully automated suite that runs inside a CI/CD pipeline.

What you will learn:

  • How to write meaningful tests for your API requests in Postman.
  • How to run those tests from the command line using Newman.
  • How to integrate Newman into a GitHub Actions pipeline to create a fully automated testing workflow.

Step 1: Writing API Tests in Postman

Before we can automate, we need a solid set of instructions for our computer to follow. In Postman, these instructions are your tests. While many use Postman as a simple client to trigger requests, its true power lies in the “Tests” tab, where you define your expectations for a response.

Let’s create a simple test. We’ll make a GET request to fetch a single post from the JSONPlaceholder API and verify a few things.

  1. Open Postman and create a new request.
  2. Set the request type to GET and the URL to
    https://jsonplaceholder.typicode.com/posts/1.
  3. Click on the Tests tab. This is where you’ll write your assertions in JavaScript.

Paste the following code into the test editor:

Step 1: Writing API Tests in Postman

Click “Save” and save this request to a new Collection called “My API Tests”. Now, when you click “Send”, you can see your test results passing in the “Test Results” tab.

Step 2: Exporting a Postman Collection for Automation

So, you’ve created your tests inside the Postman app. But how do you get them out so other tools can use them? This is a critical step for automation, and the answer is exporting. Think of it as packaging up your test instructions into a single file that another tool can read and execute.

  1. Find your “My API Tests“ collection in the left sidebar.
  2. Click the three dots (…) next to the collection name.
  3. Select “Export”.
  4. Choose the “Collection v2.1” format (it’s the recommended default).
  5. Save the file to your project directory as my-api-tests.postman_collection.json.

You now have a portable, machine-readable file containing all the requests and tests from your collection.

Step 3: Running Tests from the Command Line with Newman

Now we need a way to run our exported Postman file without manually clicking anything.

What is Newman, Exactly?

If you’ve ever searched for things like “how to run Postman collections from command line” or “run Postman without the app,” Newman is the official answer you’ve been looking for.

Newman is a powerful command-line companion to Postman. It’s a tool that takes your exported collection file and runs everything inside it, all your requests, pre-request scripts, and tests, directly from your terminal. Because it runs on the command line, it can be executed in any automated environment, which is the key that unlocks CI/CD integration.

First, let’s install Newman on your machine using npm. Open your terminal and run:

Bash

npm install -g newman

Step 3: Running Tests from the Command Line with Newman

Once installed, navigate your terminal to the directory where you saved your exported collection file. Now, run the collection with this simple command:

Bash

newman run my-api-tests.postman_collection.json

running the collection with this simple command: Bash

You should see Newman spring to life, producing a neat summary table showing all your requests, assertions, and whether they passed or failed.

Step 4: Setting Up a CI/CD Pipeline with GitHub Actions

Running a command locally is great, but the ultimate goal is to have this run automatically every time code changes. For this, we’ll turn to a CI/CD platform.

What is GitHub Actions?

GitHub Actions is an automation engine built right into GitHub. Think of it as a robot assistant for your repository. It can listen for events like a git push and automatically run a series of commands for you. It’s the perfect tool to answer the question, “how to automatically run tests when I push new code?” Instead of you remembering to run Newman, you can tell GitHub Actions to do it for you every single time.

  1. In your project folder, create a new directory structure: .github/workflows/.
  2. Inside the workflows directory, create a new file named api-tests.yml.
  3. Paste the following code into api-tests.yml:

Step 4: Setting Up a CI/CD Pipeline with GitHub Actions

Commit this file and your exported collection JSON file, and push them to your GitHub repository. GitHub will automatically detect the workflow file and execute it.

Step 5: Reviewing Automated Test Results

Automation is useless without clear feedback. When your workflow runs, go to the “Actions” tab of your GitHub repository.

You will see your workflow running. A green checkmark means all your Newman tests passed. Congratulations, your changes are safe! A red X means at least one test failed. This is your crucial safety net. Click into the failed job to see the Newman output in the logs. It will tell you exactly which assertion failed, so you know what needs to be fixed before it ever reaches your users.

This immediate, automated feedback loop is the true power of CI/CD.

Why Automate API Tests Works?

Automating your API tests isn’t just about convenience; it’s a strategic move that provides tangible benefits:

  • Speed and Efficiency: Automated tests run in seconds or minutes, a fraction of the time it takes to perform them manually. This dramatically accelerates your development and release cycles.
  • Accuracy and Consistency: Machines don’t get tired or make mistakes. Every test runs exactly the same way, every time, eliminating human error and ensuring consistent results.
  • Comprehensive Regression Coverage: An automated suite can easily cover hundreds of test cases, ensuring that new code doesn’t unintentionally break existing functionality. This safety net is crucial for maintaining a stable application.
  • Increased Confidence: When you have a robust suite of automated tests, your entire team can deploy new features with confidence, knowing that a critical layer of quality assurance is always in place.

Conclusion and Next Steps

You’ve just built a powerful safety net for your API. You’ve gone from tedious manual clicking to a robust, automated process that saves time, eliminates human error, and boosts confidence in your releases.

This is a huge first step, but the journey doesn’t end here. You can now explore:

  • HTML Reports: Use a Newman reporter like newman-reporter-html to generate beautiful, detailed reports of your test runs that you can share with your team.
  • Environment Variables: Use Postman Environments to manage variables like base URLs and API keys across different stages (development, staging, production).
  • Notifications: Configure your pipeline to send a Slack or email notification when tests fail, so you’re alerted immediately.

Building reliable software is all about creating fast feedback loops. By automating your API tests, you’ve created one of the most important loops of all.

Looking to build scalable, enterprise-grade testing strategies and DevOps pipelines? The experts at Varseno Solutions specialize in creating robust automation solutions that accelerate development and ensure quality. Contact us today.