Prompt
How do I automate tests so every pull request gets validated before merge?
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
To automate tests for every pull request before merge, set up a CI pipeline that runs whenever a PR is opened or updated, and make those checks required in your branch protection rules.
High-level flow
- Developer opens or updates a pull request.
- CI system automatically starts a test run.
- Tests pass or fail.
- Merge is blocked unless required checks pass.
Common setup
1) Choose a CI system
Popular options:
- GitHub Actions if your repo is on GitHub
- GitLab CI for GitLab
- Jenkins, CircleCI, Azure DevOps, Bitbucket Pipelines, etc.
2) Configure tests to run on PR events
Example for GitHub Actions:
name: Pull Request Tests
on:
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up runtime
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
This runs automatically on every PR targeting main.
3) Make tests mandatory before merge
In your repository settings, enable branch protection for main and require:
- the CI check to pass
- status checks to be up to date before merging
- optionally, at least one approval
For GitHub:
- Settings → Branches → Branch protection rules
- Require status checks
- Select the workflow job, e.g.
Pull Request Tests / test
Best practices
- Run fast unit tests on every PR.
- Run integration/e2e tests if needed, but keep them efficient.
- Use caching to speed up builds.
- Run tests in parallel where possible.
- Fail the build if tests fail.
- Keep PR checks deterministic and isolated from production resources.
Good extras
- Linting and formatting checks
- Type checking
- Security scans
- Code coverage reporting
- Preview environments for manual verification
Recommended minimal policy
- On every PR: lint + unit tests + type checks
- Before merge: require all checks to pass
- On merge to main: run full test suite and deployment pipeline
If you tell me your platform (GitHub/GitLab/etc.) and language/framework, I can give you an exact config file.