読み物Testing · DevOps

Level: Intermediate

Automated Testing in CI/CD: Coverage, Static Analysis, and Quality Gates

Design a testing pipeline that runs on every change: fast-first ordering, static analysis, coverage, quality gates that help rather than backfire, and release criteria.

Edeeson Opina7 min read

An Intermediate lesson card: lesson 10 of the Software Testing & Quality Engineering series, Automated Testing in CI/CD: Coverage, Static Analysis, and Quality Gates, with the Miso fox excited.

What you’ll learn

  • Order pipeline checks to fail fast
  • Use static analysis as the cheapest testing
  • Choose quality gates that help, and avoid ones that backfire
  • Write release criteria and a definition of done
On this page
  1. Before you start
  2. What a testing pipeline checks
  3. Order matters: fail fast
  4. Static analysis: the cheapest testing
  5. A testing workflow
  6. The same pipeline in other stacks
  7. Quality gates
  8. Gates that backfire
  9. Merge queues
  10. Keeping the pipeline fast
  11. Release criteria and the definition of done
  12. Test results as data
  13. Common mistakes and troubleshooting
  14. Practical exercise: build a quality gate
  15. Key takeaways
  16. References
  17. What's next

Tests protect you only when they run, on every change, before it's merged, without anyone having to remember. Continuous integration turns your test suite into a gate that every pull request must pass, alongside static analysis, coverage checks, and the other signals that tell a team whether a change is ready. This lesson designs a testing pipeline: what to run and in which order, how to keep it fast, what quality gates make sense (and which ones backfire), and how to define release criteria a team can actually trust.

Before you start

You should know the testing levels and tools from the earlier lessons, especially Test-Driven Development (TDD), Refactoring, and Maintainable Test Suites. For CI platform basics (GitHub Actions, GitLab CI/CD, Forgejo Actions), read CI/CD with Git in our Git series; this lesson focuses on the testing side.

What a testing pipeline checks

A pipeline answers one question for each change: is it safe to merge? It combines several kinds of evidence:

  • Formatting is consistent, so diffs show real changes.
  • Static analysis finds defects without running code: type errors, lint rules, suspicious patterns.
  • Unit tests check logic quickly.
  • Integration tests check connections to databases and services.
  • A build proves the artifact can be produced.
  • E2E tests check critical journeys.
  • Security checks: dependency vulnerabilities and secrets (lesson 14).

Order matters: fail fast

Put the fastest, most likely-to-fail checks first, so developers get feedback in a minute or two rather than waiting twenty minutes to learn about a missing semicolon:

  1. Install dependencies from the lockfile.
  2. Format check and lint (seconds).
  3. Type check (seconds).
  4. Unit tests (seconds to a minute).
  5. Build.
  6. Integration tests (minutes).
  7. E2E tests (minutes), possibly split across machines.

Independent jobs can run in parallel: lint, unit tests, and integration tests don't need each other.

Static analysis: the cheapest testing

Static analysis tools find whole categories of defects without writing a single test:

Shell
# TypeScript
npx tsc --noEmit
npx eslint .

# Rust
cargo fmt --check
cargo clippy --all-targets -- -D warnings

# PHP
vendor/bin/phpstan analyse

Turn warnings into failures in CI (-D warnings for Clippy, --max-warnings 0 for ESLint), or they accumulate until nobody reads them. Introduce strict rules gradually on existing code: fix new code first, then old code over time.

A testing workflow

Here's a pipeline for a TypeScript web app, on GitHub Actions. The same structure translates to GitLab CI/CD or Forgejo Actions, as the Git series shows:

.github/workflows/test.ymlYAML
name: test
on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
        with:
          node-version: 24
          cache: npm
      - run: npm ci
      - run: npm run lint
      - run: npx tsc --noEmit
      - run: npx vitest run --coverage --reporter=default --reporter=junit --outputFile.junit=reports/unit.xml

  e2e:
    needs: checks
    runs-on: ubuntu-latest
    strategy:
      matrix:
        shard: [1, 2]
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
        with:
          node-version: 24
          cache: npm
      - run: npm ci
      - run: npx playwright install --with-deps chromium
      - run: npx playwright test --shard=${{ matrix.shard }}/2

A few details worth copying:

  • Frozen installs (npm ci) test exactly what the lockfile says.
  • JUnit XML reports (reports/unit.xml) let the platform show which tests failed in the pull request view.
  • Sharding splits E2E tests across two machines; Playwright's --shard=1/2 and --shard=2/2 each run half.
  • needs: checks skips the slower E2E job when lint or unit tests already failed.
  • Actions are pinned to full commit SHAs, as the Git series explains.

The same pipeline in other stacks

The structure doesn't depend on the language. A Rust job on GitLab CI/CD follows the same fail-fast order:

.gitlab-ci.ymlYAML
rust-checks:
  image: rust:1
  script:
    - rustup component add rustfmt clippy
    - cargo fmt --check
    - cargo clippy --all-targets --locked -- -D warnings
    - cargo test --locked

And a PHP project runs composer install --no-interaction, then vendor/bin/phpstan analyse, then vendor/bin/phpunit (or vendor/bin/pest). Format and static analysis first, then tests, then the build: the order matters more than the tools. Mixed projects, such as a Tauri app with a Rust back end and a TypeScript front end, simply run both sets of jobs in parallel.

Quality gates

A quality gate is a rule a change must satisfy before merging or releasing. Branch protection (or merge request approval rules) makes the gate binding: the merge button stays disabled until required checks pass.

Useful gates:

  • All required checks pass: lint, types, unit, integration, build, and critical E2E tests.
  • At least one approving review.
  • No new high-severity dependency vulnerabilities or detected secrets.
  • Coverage doesn't drop significantly on the changed code.
  • Bundle size or performance budgets aren't exceeded (lesson 11).

Gates that backfire

Some gates create the wrong incentives:

  • A high global coverage percentage (say, 90%) encourages tests that execute code without checking anything (lesson 6). Prefer "changed lines are covered" plus review.
  • Zero warnings on a legacy codebase overnight blocks everyone, so the gate gets disabled. Ratchet: forbid new warnings, then reduce old ones.
  • Gates nobody owns. If a check fails and nobody knows why it exists, it gets bypassed. Document each gate's purpose.

Merge queues

Two pull requests can each pass CI alone and still break main when combined. A merge queue tests each change together with the ones ahead of it before merging, so main stays green on busy repositories. GitHub and GitLab both offer one.

Keeping the pipeline fast

A slow pipeline changes behavior: developers batch changes, skip running tests locally, and merge larger, riskier pull requests. Keep it fast:

  • Cache dependencies keyed on the lockfile, and build caches where the tool supports them.
  • Run only what changed in monorepos, using path filters or a build tool that understands project dependencies.
  • Parallelize: separate jobs, test sharding, and test-runner parallelism (Vitest and Playwright both run tests in parallel by default).
  • Move slow suites (long E2E, performance, mutation testing) to a nightly schedule, while keeping a critical subset on every pull request.

Track pipeline duration like any other metric. Aim for minutes, not tens of minutes, on pull requests.

Release criteria and the definition of done

Merge gates protect main; release criteria decide when a version ships. Write them down, for example:

  • All automated suites green on the release commit, including the full E2E suite.
  • No open defects of high severity in the release scope.
  • Performance and accessibility checks within budgets.
  • Security scans show no unaddressed high-severity findings.
  • Release notes written; rollback plan confirmed.

A team's definition of done applies similar criteria to each piece of work: the feature has tests at the right levels, documentation is updated, and it passes the pipeline. Agreeing on this up front stops arguments at release time.

Test results as data

Over time, CI produces valuable data: which tests fail most, which are slow, which are flaky. Look at it regularly:

  • the slowest tests (candidates for moving down a level or optimizing);
  • tests that failed and then passed on retry (flaky; lesson 15);
  • areas where defects escaped to production despite passing CI (missing tests).

Common mistakes and troubleshooting

  • Optional checks. If a failing check doesn't block merging, it will be ignored. Make important checks required.
  • Retrying failures automatically and forgetting them. Retries hide flaky tests; record and fix them.
  • One huge job. Split it so the fastest checks report first and jobs run in parallel.
  • Different commands locally and in CI. Use the same scripts in both.
  • "Works locally, fails in CI." Compare runtime versions, time zones (set TZ=UTC in tests), locales, environment variables, and missing services or browsers.
  • Coverage drops unnoticed. Report coverage on the pull request, focused on changed lines.

Practical exercise: build a quality gate

  1. Write a CI workflow for a small project that runs format check, lint, type check, and unit tests, fastest first.
  2. Add a JUnit report and confirm failed tests appear in the pull request view.
  3. Make the workflow a required check on the main branch, with one required review.
  4. Open a pull request with a deliberately failing test and confirm merging is blocked.
  5. Add E2E tests split into two shards, depending on the first job.
  6. Write five release criteria for your project and add them to the repository's documentation.

Key takeaways

  • A testing pipeline answers "is it safe to merge?" with formatting, static analysis, tests at several levels, builds, and security checks.
  • Run the fastest checks first, parallelize the rest, and keep pull request pipelines to minutes.
  • Static analysis is the cheapest testing; treat warnings as errors in CI.
  • Make important checks required; prefer gates on changed code over global coverage targets.
  • Write down release criteria and a definition of done, and use CI data to find slow and flaky tests.

References

What's next

You've finished the Intermediate level. The Pro level starts with qualities beyond correctness: Performance and Reliability Testing: Load, Stress, Soak Testing, and Benchmarks.

See every lesson in Software Testing & Quality Engineering: From Fundamentals to Production-Ready Software