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:
# 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 pushCode Push → Unit Tests → Integration Tests → Contract Tests → Deploy → Smoke Tests
(pytest) (Newman) (Pact) (CD) (smoke_test.py)
│
Nightly ──→ Load Tests (k6)
All tools follow Unix conventions:
Your CI pipeline should fail the build on non-zero exit codes.
# 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# 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_URLPart of API Developer Pro. Support: support@datanest.dev
How to use the included k6 scripts to understand your API's performance characteristics.
| Script | Purpose | When to Run |
|---|---|---|
load-test.js | Find baseline performance | Weekly, before releases |
stress-test.js | Find the breaking point | Before scaling decisions |
spike-test.js | Test sudden traffic surges | Before marketing events |
# 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 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:
Each test script defines thresholds that determine pass/fail:
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).
Before load testing, establish your baseline:
| Metric | Acceptable | Good | Excellent |
|---|---|---|---|
| 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
Get the full API Testing Automation and unlock everything.
Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.
Access all interactive tools with complete data, all workload profiles, and the full scenario library.
Downloadable source code, configuration files, and working examples from every chapter.
Free updates for life. Every new chapter, tool, and improvement included.