Which tests at which stage of the pipeline
Tests are laid out across pipeline stages: the closer to the commit, the faster and more stable. A merge request runs lint, unit, API and a few critical E2E tests; after the merge come wider integration tests; the full regression runs nightly; before a release regression and UAT; after the deploy a short check. Only fast, reliable checks block a merge. Flaky tests go to quarantine with an owner and a deadline.
QA Fundamentals · Processes and Agile
The pipeline on every commit takes an hour. Which tests stay on the merge and which move out?
In a team a merge request waits forty-five minutes for a green pipeline, because every commit runs the full E2E regression. Developers merge in big batches so as not to wait several times, one flaky failure forces a restart of everything, and a defect that a unit test would catch in seconds shows up only an hour later. The problem is not the tests but that they are all in one place. This lesson is about which tests to run at which stage of the pipeline, by what principle to lay them out and what exactly blocks a merge.
How it works and why. Two opposite demands apply: fast feedback and confidence. The closer a check is to the commit, the sooner the developer learns about a problem while they still remember the code, but the less time it can take. The deeper a check is (a full E2E regression, several browsers, visual and load tests), the more confidence it gives, but the longer and more expensive it is. So tests are laid out on the pyramid principle (many fast ones, fewer slow ones) and run in stages: cheap and fast first, while later ones run less often and only if the previous ones have passed. This is fail fast: it is better to find an error in a minute than in an hour.
A stage that blocks the move forward (a merge, a deploy to stage, a release) is called a quality gate. It is worth blocking only with what passes quickly and gives a reliable signal. What is long or prone to instability is moved off the blocking path so that it does not slow down the whole team.
Pipeline stages and what runs at each
| Stage | What we run | Why |
|---|---|---|
| Commit / merge request | A linter, type checks, unit tests, fast API tests, a small set of critical E2E | An answer in a few minutes: did I break the basics |
| After the merge, deploy to dev or stage | Integration tests, critical E2E scenarios | Whether the components work together on a live environment |
| Nightly | Full E2E regression on several browsers, visual regression, basic performance and security checks | Wider coverage without slowing development |
| Before the release | Full regression on staging, UAT, manual testing of new features | Final confidence before the go or no-go decision |
| After the deploy to production | A short check of critical flows, monitoring | To confirm that the same thing works in production |
Unstable (flaky) tests must not block the pipeline: they are isolated in quarantine and fixed separately. A quarantine has an owner and a deadline, otherwise it turns into a graveyard of tests.
Example: from one big job to laid-out stages. The initial version: everything in every merge request.
# Before: the whole E2E regression in every merge request
e2e-all:
script: npx playwright test
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
The result: a long wait, big batches instead of frequent small merges and failures whose cause is hunted among hundreds of tests. The laid-out version in GitLab CI syntax (in GitHub Actions or Jenkins the same ideas are expressed differently):
# After: fast on commit, deeper later
stages: [verify, stage, nightly]
unit-api: # blocks the merge
stage: verify
script: [npm run lint, npm run test:unit, npm run test:api]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
e2e-fast: # only critical tests tagged @fast
stage: verify
script: npx playwright test --grep @fast
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
e2e-critical: # after the merge, on stage
stage: stage
script: npx playwright test --grep @critical
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
e2e-full: # on a schedule, does not block
stage: nightly
script: npx playwright test --project=chromium --project=firefox
allow_failure: true
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
How to read it. A merge request runs only the fast checks: lint, unit, API and a small set of E2E tagged @fast, that is, the critical paths that must be stable. After the merge into the main branch a wider set of critical tests runs. The full regression on two browsers runs on a schedule and has allow_failure: true, so it does not block, and the team goes through the result in the morning. Such a layout keeps both speed and coverage: full coverage has not disappeared anywhere, it just stands where its delay bothers nobody.
The tags @fast and @critical are a team agreement, not a tool requirement. The harder question is which tests get which tag. The principle is this: the fast set gets the scenarios whose failure stops all work (sign-in, the main flow), and only those that are stable.
Limits and alternatives. Laying out by stages is not the only way to cut time. Parallelisation and sharding split tests among several agents, change analysis runs only the tests for changed modules (critical in a monorepo), and caching dependencies removes extra minutes. In microservices each service has its own fast pipeline with contract tests, and end-to-end checks are moved to a separate stage. Integration tests need an environment that costs money and may be unstable, so they run after the merge, not on every commit. A nightly run does not remove responsibility: if nobody looks at the result it is useless. An owner and a rule are needed that a failure is looked at the same morning. Not everything is automated: exploratory testing of a new feature remains a manual stage that cannot be built into a pipeline.
Common mistakes.
- Running the whole E2E regression on every commit: the queue grows, merging in big batches becomes the norm and the pipeline itself puts developers off.
- Making unstable tests blocking: the team starts rerunning "until green" and the signal loses its meaning.
- Setting up a nightly run without an owner: red results touch nobody and regression accumulates unnoticed.
- Duplicating the same check at every stage: time grows while there is no new information.
- Forgetting a quarantine with a deadline: a flaky test was switched off "temporarily" and forgotten, and coverage quietly shrank.
- Postponing everything to the pre-release regression: problems that could have been found at the commit show up a day before the release.
Check yourself
The MR pipeline takes 50 minutes because it runs the whole E2E regression. What do you move out, what do you keep and why?
Answer
On the MR I keep what is fast and stable: lint, unit, API tests and a small set of critical E2E. I move the full regression on several browsers and the visual tests to nightly, and keep the critical integration and E2E after the merge on stage. Coverage does not disappear, while feedback on the commit returns in minutes. Additionally I can parallelise and run only the tests for the changed modules.
The nightly run is red on three tests every morning and nobody looks. What is wrong with the process?
Answer
Non-blocking does not mean ignored. An owner of the result and a rule are needed that a failure is looked at the same morning: it is either a defect (a bug) or an unstable test (quarantine with a deadline and a fix). Without that the signal is noisy, the team gets used to red and a real regression gets lost in it.