Contents

Chapter 1

CI/CD Integration Guide

How to integrate API tests into your CI/CD pipeline using GitHub Actions, GitLab CI, or Jenkins.

See newman/github-actions.yml for a complete workflow that:

  • Runs on every push to main/develop
  • Runs on pull requests
  • Runs on a schedule (every 6 hours)
  • Supports manual triggers with environment selection
  • Uploads HTML test reports as artifacts

Quick Setup

bash
# 1. Copy the workflow file
mkdir -p .github/workflows
cp newman/github-actions.yml .github/workflows/api-tests.yml

# 2. Add secrets in GitHub Settings > Secrets > Actions
#    - API_BASE_URL
#    - API_TEST_EMAIL
#    - API_TEST_PASSWORD

# 3. Push and watch it run
git add .github/workflows/api-tests.yml
git commit -m "Add API test workflow"
git push

Pipeline Architecture

Code Push → Unit Tests → Integration Tests → Contract Tests → Deploy → Smoke Tests
              (pytest)     (Newman)            (Pact)          (CD)    (smoke_test.py)
                                                                         │
                                                                    Nightly ──→ Load Tests (k6)

Exit Codes

All tools follow Unix conventions:

  • 0: All tests passed
  • 1: Test failures detected
  • 2: Configuration error

Your CI pipeline should fail the build on non-zero exit codes.

Running Newman in CI

bash
# Basic run
newman run postman/collection.json -e postman/environment.json

# With environment variable overrides (for CI secrets)
newman run postman/collection.json \
  -e postman/environment.json \
  --env-var "base_url=$API_BASE_URL" \
  --env-var "test_email=$API_TEST_EMAIL" \
  --reporters cli,htmlextra \
  --bail

Running k6 in CI

bash
# Install k6 (Ubuntu)
sudo gpg -k && sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D68 && echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list && sudo apt-get update && sudo apt-get install k6

# Run load test
k6 run k6/load-test.js --env BASE_URL=$API_BASE_URL

Part of API Developer Pro. Support: support@datanest.dev

Chapter 2

Load Testing Guide with k6

How to use the included k6 scripts to understand your API's performance characteristics.

Test Types

ScriptPurposeWhen to Run
load-test.jsFind baseline performanceWeekly, before releases
stress-test.jsFind the breaking pointBefore scaling decisions
spike-test.jsTest sudden traffic surgesBefore marketing events

Running Tests

bash
# Standard load test
k6 run k6/load-test.js

# With custom base URL
k6 run --env BASE_URL=https://staging.example.com/v1 k6/load-test.js

# Output results to JSON for analysis
k6 run --out json=results.json k6/load-test.js

# Output to InfluxDB for Grafana dashboards
k6 run --out influxdb=http://localhost:8086/k6 k6/load-test.js

Reading k6 Results

     checks.........................: 95.23% 1904 out of 2000
     data_received..................: 12 MB  198 kB/s
     data_sent......................: 1.2 MB 20 kB/s
     http_req_duration..............: avg=142ms min=12ms med=98ms max=2.1s p(90)=312ms p(95)=489ms
     http_req_failed................: 2.15%  43 out of 2000
     iterations.....................: 2000   33.33/s

Key metrics to watch:

  • p95 duration: 95% of requests complete within this time
  • http_req_failed: Percentage of failed requests
  • iterations/s: Throughput (requests per second)
  • checks: Percentage of assertions that passed

Thresholds

Each test script defines thresholds that determine pass/fail:

javascript
thresholds: {
    http_req_duration: ['p(95)<500'],   // 95th percentile under 500ms
    http_req_failed: ['rate<0.05'],     // Less than 5% failure rate
}

If any threshold is breached, k6 exits with code 99 (threshold failure).

Performance Baselines

Before load testing, establish your baseline:

MetricAcceptableGoodExcellent
p95 latency< 1000ms< 500ms< 200ms
p99 latency< 3000ms< 1000ms< 500ms
Error rate< 5%< 1%< 0.1%
Throughput> 100 rps> 500 rps> 2000 rps

Part of API Developer Pro. Support: support@datanest.dev

Chapter 3
🔒 Available in full product

API Testing Strategy Guide

You’ve reached the end of the free preview

Get the full API Testing Automation and unlock everything.

All Chapters

Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.

Full Tool Suite

Access all interactive tools with complete data, all workload profiles, and the full scenario library.

Source Files

Downloadable source code, configuration files, and working examples from every chapter.

Lifetime Updates

Free updates for life. Every new chapter, tool, and improvement included.

Buy Now — $29 →
📦 Free sample included — download another copy for the full product.
API Testing Automation v1.0.0 — Free Preview