Testing and quality gates

AZ-400 DevOps EngineerBuild and release pipelinesAbout 25 minutesBy Cloud Hands On

A testing strategy from local to load tests, running tests in pipelines, code coverage, and quality, release and security gates.

In this lesson you'll learn

1. A testing strategy

The test pyramid

Have many fast, cheap tests at the bottom and few slow, expensive ones at the top: lots of unit tests, fewer integration tests, and a small number of end-to-end and UI tests. Run the fast ones on every commit; run slower ones later in the pipeline.

TestChecksWhen
Local testsDeveloper runs unit tests and linters before pushingBefore commit
Unit testsOne function or class in isolationEvery build
Integration testsComponents together, real database or APIAfter build, in a test environment
Load testsBehaviour under many users (Azure Load Testing, JMeter, k6)Before release, or on a schedule

This is shift left: find problems as early as possible, where they're cheapest to fix.

2. Tests in a pipeline

Run tests with the language's tool (dotnet test, npm test, the VSTest task) and publish results with PublishTestResults@2 (JUnit, NUnit, xUnit, VSTest formats). Results appear on the run's Tests tab, failures can fail the run, and Azure Pipelines tracks history and detects flaky tests.

UI and browser tests may need a test agent with a desktop session or particular browsers: a self-hosted agent or a container with the browser installed. Tests that need private resources need an agent that can reach them.

In GitHub Actions, test steps fail the job on a non-zero exit code; actions or reporters publish results as checks and summaries.

3. Code coverage

Coverage shows which code the tests ran. Collect it in Cobertura or JaCoCo format and publish it with PublishCodeCoverageResults@2. Coverage is a guide, not a goal: 100% coverage with weak assertions proves little. Pull request checks can require that coverage of changed lines stays above a threshold.

4. Quality and release gates

A gate stops a release until a condition is met. In YAML pipelines, gates are checks on environments: manual approvals, branch control (only main may deploy to production), business hours, Invoke Azure Function or REST API, Query Azure Monitor alerts (stop if production is unhealthy), required template and exclusive lock. Classic release pipelines have pre- and post-deployment gates with similar options.

Security and governance gates include: no critical vulnerabilities from scanning, policy compliance (Azure Policy), sign-off from a change approver, and quality thresholds such as SonarQube's quality gate.

Example

SS Kaiser's pipeline runs unit tests on every commit, integration tests in a test environment, and a 10-minute load test nightly. The production environment has two checks: an approval from the release manager, and an Azure Monitor alerts query that blocks the deployment if the shop has active Sev 1 alerts.

Exam traps to remember

  • In YAML, approvals and gates are checks on an environment, not steps in the file.
  • PublishTestResults publishes test outcomes; PublishCodeCoverageResults publishes coverage.
  • Query Azure Monitor alerts is the check that stops deployments when production is unhealthy.

Test yourself: 3 check questions and exam-style practice questions on this topic are in the AZ-400 DevOps Engineer app.

Practise in the app

Keep going