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

End-to-end CI/CD (1/5): principles and anatomy of a pipeline

Understand end-to-end CI/CD: continuous integration, continuous delivery and continuous deploymen...

k6 in continuous integration and on Kubernetes (k6-operator)

Automate performance tests: k6 in GitHub Actions and GitLab CI with blocking thresholds, distribu...

End-to-end CI/CD (3/5): artifacts, registries and environments

Deliver continuously: immutable, versioned artifacts, image and package registries, promoting the...

End-to-end CI/CD (4/5): deployment strategies and rollback

Deploy without downtime and without risk: recreate, rolling update, blue/green, canary, feature f...

DevOps best practices: culture, CI/CD, infrastructure as code and measurement

DevOps best practices: culture and collaboration, continuous integration and delivery, trunk-base...

Ansible: going further (testing, quality, CI/CD and performance)

Industrialize Ansible: ansible-lint, yamllint, Molecule, continuous integration, collections, exe...

End-to-end CI/CD (5/5): GitHub Actions, GitLab CI, Jenkins and Argo CD in practice

Compare and use CI/CD tools: GitHub Actions, GitLab CI, Jenkins, Argo CD and Flux; a complete pip...

Measuring DevOps performance: DORA metrics, SPACE and continuous improvement

Measure and improve delivery performance: the DORA metrics (deployment frequency, lead time, chan...

Testing and securing Terraform: validate, terraform test, tflint, Checkov and policies

Ensure the quality of Terraform code: fmt and validate, native terraform test tests with mocked p...

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!