RousselTMLEARNING

Article · DevOps: From Discovery to Expertise

CI/CD (2/5): continuous integration, tests and quality

1. The discipline of continuous integration #

More than a build server.

The rules #

  1. Everyone integrates into the main branch at least once a day.
  2. Every integration triggers an automatic build and tests.
  3. The build is fast: less than 10 minutes for the commit stage.
  4. A broken build is fixed immediately, taking priority over everything else.
  5. Everyone can see the build status and get the latest artifact.
Key takeaway: Having Jenkins or GitHub Actions is not enough: branches that live three weeks without integration are not continuous integration, even with a pipeline.

2. Tests #

The safety net of CI/CD.

The pyramid #

Test pyramid
Invest at the base: fast, reliable tests give feedback within minutes.
TypeChecksTools (examples)
Unitan isolated function or classpytest, JUnit, Jest, go test
Integrationthe code with a real database, a real queueTestcontainers, docker compose
Contractthat an API provider meets what its consumers expectPact, OpenAPI schemas
End-to-enda complete user journeyPlaywright, Cypress
Performanceresponse times and behavior under loadk6, Gatling
Securitycode, dependencies, imagesSemgrep, Trivy, OWASP ZAP

Realistic integration tests #

# pytest + Testcontainers : une vraie base PostgreSQL éphémère pour chaque exécution
from testcontainers.postgres import PostgresContainer
import psycopg

def test_insertion_commande():
    with PostgresContainer("postgres:16") as pg:
        with psycopg.connect(pg.get_connection_url().replace("+psycopg2", "")) as conn:
            conn.execute("CREATE TABLE commandes (id serial, total numeric)")
            conn.execute("INSERT INTO commandes (total) VALUES (42)")
            assert conn.execute("SELECT count(*) FROM commandes").fetchone()[0] == 1

Flaky tests #

A test that fails « sometimes » destroys trust: the team reruns the pipeline without reading the error, and ends up ignoring a real problem.

Good practice: Quarantine a flaky test (marked, non-blocking) with a ticket, fix it quickly (explicit waits, isolated data, mocked clock) and track the pipeline rerun rate.

3. Quality and quality gates #

Automatic rules, not debates in review.

Static analysis #

ruff check . && ruff format --check .      # Python : lint et formatage
mypy src/                                  # typage
eslint . && prettier --check .             # JavaScript
hadolint Dockerfile                        # bonnes pratiques Dockerfile
shellcheck scripts/*.sh
gitleaks detect --source .                 # secrets commités

Quality gate #

Example quality gate
Thresholds apply to new code, so as not to block because of legacy.

A quality gate is a set of blocking conditions (SonarQube, branch protection rules). Measure coverage of new code rather than a global percentage: requiring 80% on a codebase at 30% blocks everything and pushes people to write hollow tests.

Common mistake: Coverage measures the code executed by tests, not the quality of the assertions: a test without assertions « covers » code without checking anything.

4. A fast pipeline #

Keeping feedback under 10 minutes.

Techniques #

TechniqueEffect
Dependency cacheavoids re-downloading at each build
Parallelizing and splitting testsdivides duration by the number of runners
Matrixtests several versions (language, OS) in parallel
Selective executionrun only what is affected (monorepo: changed paths)
Docker layer cacherebuilds only changed layers
Cancelling obsolete buildsa new push cancels the previous pipeline of the same branch
jobs:
  test:
    strategy:
      matrix:
        python: ["3.11", "3.12", "3.13"]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: "${{ matrix.python }}", cache: pip }
      - run: pip install -r requirements.txt && pytest -q -n auto   # pytest-xdist
concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

📄 End-to-end CI/CD (2/5): continuous integration, testing and quality →

My progress

  • ⏱ Estimated time : ≈ 7 min

Sign in to track your progress and take notes. Sign in

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

DevSecOps: securing the software supply chain end to end

Integrate security into the DevOps pipeline: shift-left, threat modeling, secret detection, SAST,...

Infrastructure as Code and GitOps: Terraform, Ansible and Argo CD

Manage infrastructure as code: declarative or imperative, Terraform (providers, state, plan, modu...

Git for DevOps: branches, code reviews and versions

Organize work with Git in a DevOps approach: trunk-based development or GitFlow, short-lived bran...

Load testing with Grafana k6: why, and which types of tests

Why test performance before production, the types of tests (smoke, load, stress, spike, soak, bre...

Observability, SRE and incident management for DevOps teams

Operate what you ship: metrics, logs and traces, golden signals, SLIs, SLOs and error budgets, ac...

Ansible best practices: structure, idempotence, security and quality

Ansible best practices: project organization, naming, FQCN, idempotence, modules rather than shel...

Platform engineering, FinOps and AI: the new frontiers of DevOps

Understand how DevOps is evolving: platform engineering and internal developer platforms (IDP), g...

DevOps variants: understanding how engineering culture has evolved

Discover the different flavors of DevOps: DevSecOps, AIOps, NoOps, GitOps and FinOps. Understand ...

Organizing DevOps: value streams, teams and a blameless culture

Set up a DevOps organization: value chain and value stream mapping, Team Topologies, « you build ...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!