DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

lab: WHY DevOps Engineers Use Postman + Newman

Postman (Manual + Design Phase)

Used by DevOps to:

  • Test APIs before deployment
  • Validate endpoints (GET, POST, DELETE)
  • Work with developers (API contract testing)
  • Save collections for automation

Newman (Automation Phase)

CLI tool to:

  • Run Postman collections in CI/CD
  • Validate APIs after deployment
  • Block bad releases automatically

πŸ‘‰ Key Idea:

  • Postman = Manual testing
  • Newman = Automated testing in pipeline

πŸ”₯ 2. WHAT TESTS DEVOPS ENGINEERS DO

1. Health Check Test

GET /health
Enter fullscreen mode Exit fullscreen mode

Check:

  • API is alive
  • Returns 200

2. Functional Test

POST /users
Enter fullscreen mode Exit fullscreen mode

Check:

  • Response contains correct data
  • Fields match expected

3. Status Code Validation

pm.test("Status is 200", function () {
    pm.response.to.have.status(200);
});
Enter fullscreen mode Exit fullscreen mode

4. Response Body Validation

pm.test("User created", function () {
    let json = pm.response.json();
    pm.expect(json.name).to.eql("Aisalkyn DevOps");
});
Enter fullscreen mode Exit fullscreen mode

5. Performance Check (Basic)

pm.test("Response time < 500ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(500);
});
Enter fullscreen mode Exit fullscreen mode

6. Schema Validation (Advanced DevOps)

Validate structure:

pm.test("Response has id", function () {
    let json = pm.response.json();
    pm.expect(json).to.have.property("id");
});
Enter fullscreen mode Exit fullscreen mode

7. Negative Testing

POST /users (invalid body)
Enter fullscreen mode Exit fullscreen mode

Check:

  • API rejects bad input
  • Returns 400

πŸ”₯ 3. LAB β€” COMPLETE STRUCTURE (REAL DEVOPS)

πŸ“ Project Structure

postman-newman-lab/
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── api-test.yml
β”œβ”€β”€ collection.json
β”œβ”€β”€ environment.json
└── README.md
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ 4. STEP-BY-STEP LAB

βœ… Step 1 β€” Create Postman Collection

Use API:

https://reqres.in/api/users
Enter fullscreen mode Exit fullscreen mode

POST Request

Body:

{
  "name": "Aisalkyn DevOps",
  "job": "Cloud Engineer"
}
Enter fullscreen mode Exit fullscreen mode

βœ… Step 2 β€” Add Tests in Postman

Go to Tests tab:

pm.test("Status code is 201", function () {
    pm.response.to.have.status(201);
});

pm.test("Response has name", function () {
    let json = pm.response.json();
    pm.expect(json.name).to.eql("Aisalkyn DevOps");
});
Enter fullscreen mode Exit fullscreen mode

βœ… Step 3 β€” Create Environment

base_url = https://reqres.in/api
Enter fullscreen mode Exit fullscreen mode

βœ… Step 4 β€” Export Files

Export:

  • Collection β†’ collection.json
  • Environment β†’ environment.json

βœ… Step 5 β€” Install Newman

npm install -g newman
Enter fullscreen mode Exit fullscreen mode

Run locally:

newman run collection.json -e environment.json
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ 5. GITHUB ACTIONS (REAL PIPELINE)

.github/workflows/api-test.yml

name: API Tests

on:
  push:
    branches:
      - main

jobs:
  test-api:
    runs-on: ubuntu-latest

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

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

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

      - name: Run API Tests
        run: newman run collection.json -e environment.json
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ 6. WHY IT WORKS IN POSTMAN BUT FAILS IN GITHUB ACTIONS

❌ 1. Missing Environment Variables

Postman has:

{{base_url}}
Enter fullscreen mode Exit fullscreen mode

GitHub β†’ doesn't know it

πŸ‘‰ Fix:

  • Ensure environment.json is included

❌ 2. Hardcoded Localhost

Works locally:

http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

Fails in CI because:

  • No local server running

❌ 3. Authentication Missing

Postman:

  • Uses saved token

GitHub:

  • No token

❌ 4. Collection Uses Variables Not Defined

Example:

{{user_id}}
Enter fullscreen mode Exit fullscreen mode

❌ 5. Network Restrictions / API Down


πŸ”₯ 7. WHY WE PUSH TO GITHUB

We push because:

1. CI/CD Automation

  • Every push β†’ API tested automatically

2. Prevent Broken Deployments

  • If tests fail β†’ pipeline fails

3. Team Collaboration

  • Everyone uses same tests

4. Version Control

  • Track API changes

πŸ”₯ 8. WHAT OUTPUT WE GIVE TO MANAGER

Example Report:

API Test Report

  • Total Requests: 10
  • Passed: 9
  • Failed: 1
  • Success Rate: 90%
  • Avg Response Time: 320ms

Failed Endpoint:

POST /users β†’ 500 error
Enter fullscreen mode Exit fullscreen mode

Newman Report Command (Advanced)

newman run collection.json \
-e environment.json \
-r cli,html \
--reporter-html-export report.html
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ You send:

  • HTML report
  • Logs
  • Pipeline status

πŸ”₯ 9. REAL DEVOPS SCENARIO

Pipeline flow:

Developer pushes code
        ↓
Build (Docker)
        ↓
Deploy (ECS / Kubernetes)
        ↓
Run Newman Tests
        ↓
IF FAIL β†’ rollback
IF PASS β†’ release
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ 10. WHAT INTERVIEWERS EXPECT

You should say:

  • "We use Postman for API validation and Newman in CI/CD pipelines"
  • "We validate status codes, response body, schema, and performance"
  • "Newman helps prevent bad deployments"
  • "Failures in CI usually happen due to missing env variables or auth"

Top comments (0)