Prompt
How do I run API tests in CI/CD with GitHub Actions?
Latest observation
Oct 6, 2026
OpenAI APIWeb search: off
You can run API tests in GitHub Actions by adding a workflow that:
- checks out your code,
- starts any required services,
- installs dependencies,
- runs your API test suite,
- reports the result back to GitHub.
Typical setup
1) Put your API tests in the repo
Common tools:
- Postman/Newman
- pytest + requests
- Jest + supertest
- Playwright API testing
- Karate
2) Create a GitHub Actions workflow
Example for a Node.js project using Newman:
name: API Tests
on:
push:
branches: [main]
pull_request:
jobs:
test-api:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Run API tests
run: npx newman run tests/postman_collection.json -e tests/env.json
If your API needs a running backend
If the API under test must be started in CI, use a service container or start the app first.
Example: start app, then test it
name: API Tests
on: [push, pull_request]
jobs:
test-api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Start API server
run: npm start &
- name: Wait for API
run: npx wait-on http://localhost:3000/health
- name: Run tests
run: npm test
Example with Docker Compose
If your API depends on a database or Redis:
name: API Tests
on: [push, pull_request]
jobs:
test-api:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: testdb
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U test"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
env:
DATABASE_URL: postgresql://test:test@localhost:5432/testdb
run: pytest tests/api
Best practices
- Run tests on pull requests and main branch pushes.
- Use secrets for credentials:
env: API_KEY: ${{ secrets.API_KEY }} - Make tests idempotent and independent.
- Add a health check before testing.
- Publish test reports if needed.
- Separate smoke tests (fast) from full regression tests.
Useful additions
- Artifacts: upload logs or reports
- Matrix testing: run against multiple environments
- Environment-specific configs: dev/staging/test
Example artifact upload:
- name: Upload test report
uses: actions/upload-artifact@v4
with:
name: api-test-report
path: reports/
If you tell me your stack (Node, Python, Java, Postman, Docker, etc.), I can give you a ready-to-use workflow file.