DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

lab with Newman API

When you push code → pipeline will:

  1. Install Node.js
  2. Install Newman
  3. Run your exported Postman collection
  4. Fail if API tests fail

Step 1 — Prepare your repo

Create a GitHub repo (or use existing)

Structure:

project/
├── .github/
│   └── workflows/
│       └── api-test.yml
├── devops-lab.json
Enter fullscreen mode Exit fullscreen mode

👉 Put your exported file here:

devops-lab.json
Enter fullscreen mode Exit fullscreen mode

Step 2 — Create GitHub Actions file

Create file:

.github/workflows/api-test.yml
Enter fullscreen mode Exit fullscreen mode

Step 3 — Add this code (READY, CLEAN)

name: API Tests with Newman

on:
  push:
    branches: [ "main" ]

jobs:
  run-api-tests:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'

      - name: Install Newman
        run: npm install -g newman

      - name: Run Postman Collection
        run: newman run devops-lab.json
Enter fullscreen mode Exit fullscreen mode

Step 4 — Push to GitHub

git add .
git commit -m "add api test pipeline"
git push origin main
Enter fullscreen mode Exit fullscreen mode

Step 5 — Go to GitHub

👉 Open your repo
👉 Click Actions tab

You will see:

API Tests with Newman → Running
Enter fullscreen mode Exit fullscreen mode

Expected result

If everything works:

✔ Status is 200
✔ Response is not empty
Enter fullscreen mode Exit fullscreen mode

Job status:

✅ SUCCESS
Enter fullscreen mode Exit fullscreen mode

What happens if API breaks?

Example:

  • API returns 500
  • Test fails

Then:

❌ FAILED
Enter fullscreen mode Exit fullscreen mode

👉 Pipeline stops
👉 Deployment blocked


Real DevOps Flow (IMPORTANT)

Developer pushes code
        ↓
GitHub Actions runs
        ↓
Deploy app (optional step)
        ↓
Run Newman tests
        ↓
If FAIL → stop
If PASS → continue
Enter fullscreen mode Exit fullscreen mode

Step 6 — (OPTIONAL but PRO LEVEL)

Add environment file:

dev.json
Enter fullscreen mode Exit fullscreen mode

Then run:

- name: Run Postman Collection
  run: newman run devops-lab.json -e dev.json
Enter fullscreen mode Exit fullscreen mode

Interview answer (use this)

“I integrate Postman collections into GitHub Actions using Newman. The pipeline runs API tests automatically after code changes and fails the build if any validation fails.”

Top comments (0)