Courseiva
Design and implement build and release pipelinesmediumMultiple ChoiceObjective-mapped

Enforcing an 80% Code Coverage Threshold Without Blocking Passing Tests

Your CI pipeline includes a step that runs unit tests. You want to fail the pipeline if code coverage drops below 80%, but continue if tests pass with lower coverage. How should you configure the test step?

Quick Answer

The PublishCodeCoverageResults task's codeCoverageThreshold setting is exactly what's needed here — it evaluates the coverage report after tests finish and fails the build specifically when coverage drops below the configured percentage, while still letting a run with passing tests but sub-threshold coverage complete normally right up until that gate is checked.

⚠ Common exam trap

Many exam-takers confuse enabling code coverage collection (VSTest with 'codeCoverageEnabled') with enforcing a coverage threshold, which requires a separate task like 'PublishCodeCoverageResults' that explicitly evaluates and fails the build.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Use the 'PublishCodeCoverageResults' task with a 'codeCoverageThreshold' setting.

The 'PublishCodeCoverageResults' task with a 'codeCoverageThreshold' setting is correct because it allows you to define a minimum coverage percentage (e.g., 80%) and fail the pipeline if that threshold is not met, while still allowing the pipeline to continue if tests pass but coverage is lower. This task evaluates the coverage report after tests run and enforces the threshold as a build failure condition, not a test failure.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Configure a quality gate in the release pipeline to check coverage.

    Why it's wrong here

    Quality gates are for release, not build.

  • Add a script task that reads the coverage report and prints a warning.

    Why it's wrong here

    Warnings do not fail the pipeline.

  • Use the 'PublishCodeCoverageResults' task with a 'codeCoverageThreshold' setting.

    Why this is correct

    This task can fail the pipeline if coverage is below threshold.

  • Use the VSTest task with the 'codeCoverageEnabled' option set to true.

    Why it's wrong here

    VSTest does not have a threshold parameter.

About these practice questions

One of 823 original AZ-400 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

5 more ways this is tested on AZ-400

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. You are designing a build pipeline for a Node.js application. The pipeline must run unit tests and publish code coverage results to Azure Pipelines. Which task should you use to ensure coverage results are available in the pipeline summary?

medium
  • A.PublishTestResults@2
  • B.VSTest@2
  • C.CopyFiles@2
  • D.PublishCodeCoverageResults@1

Why D: The PublishCodeCoverageResults@1 task is specifically designed to publish code coverage results (e.g., Cobertura, JaCoCo, or .coverage formats) to Azure Pipelines, making them visible in the pipeline summary and the Tests tab. This task consumes coverage data files generated by a previous test run and integrates them into the pipeline's reporting UI.

Variation 2. Your team uses Azure Pipelines to build a Node.js application. The build pipeline runs linting, unit tests, and creates a production build. You want to ensure that the pipeline fails if the test coverage drops below 80%. You need to implement this check. What should you do?

easy
  • A.Configure a pipeline variable 'CoverageThreshold' and use it in a gate.
  • B.Set a branch policy that requires code coverage to be at least 80%.
  • C.Use the 'Visual Studio Test' task with code coverage enabled and set the 'Minimum coverage' option.
  • D.Add a 'Publish Test Results' task with code coverage enabled, then use a 'Script' task that reads the coverage report and fails if below 80%.

Why D: The 'Publish Test Results' task can publish code coverage reports, and a subsequent script task can parse the report (e.g., using a tool like c8 or nyc) and exit with a non-zero code if coverage is below 80%, causing the pipeline to fail. Option A is incorrect because a pipeline variable alone cannot enforce coverage thresholds; you need a task that checks the coverage. Option B is incorrect because branch policies can enforce code review requirements but not specific code coverage percentages from build results. Option C is incorrect because the 'Visual Studio Test' task is designed for .NET applications, not Node.js; it does not work with Node.js coverage reports.

Variation 3. You are designing a build pipeline that uses a combination of tasks. The pipeline must compile code, run unit tests, and then publish code coverage results. The tasks are: Visual Studio Build, Visual Studio Test, and Publish Code Coverage Results. Which task should be performed first?

medium
  • A.Visual Studio Build
  • B.Visual Studio Test
  • C.Publish Code Coverage Results

Why A: The correct order of tasks is: first Visual Studio Build to compile code, then Visual Studio Test to run unit tests, and finally Publish Code Coverage Results. Since the question asks for the first task in the sequence, the correct answer is Visual Studio Build (Option A).

Variation 4. You are implementing a CI pipeline for a Node.js application. The pipeline must run unit tests and generate code coverage reports. You want to publish the coverage results to Azure DevOps and enforce a minimum coverage threshold of 80%. Which tasks should you use?

medium
  • A.Use the Publish Test Results task to publish coverage data.
  • B.Use the Publish Build Artifacts task with coverage files.
  • C.Use the Copy Files task to copy coverage files and then the Publish Build Artifacts task.
  • D.Use the Publish Code Coverage Results task and configure the threshold in the task settings.

Why D: The Publish Code Coverage Results task is specifically designed to publish code coverage data (e.g., Cobertura or JaCoCo XML reports) to Azure DevOps and supports configuring a minimum coverage threshold directly in its settings. This meets both requirements: publishing results and enforcing the 80% threshold. Other tasks like Publish Test Results or Publish Build Artifacts do not natively handle coverage threshold enforcement.

Variation 5. You are designing a pipeline to build a .NET Core application. The build must run unit tests and publish code coverage results. Which task should you use to publish the code coverage results to Azure DevOps?

medium
  • A.Use the 'PublishCodeCoverageResults@1' task.
  • B.Use the 'PublishTestResults@2' task.
  • C.Use the 'DotNetCoreCLI@2' task with the 'test' command.
  • D.Use the 'VSTest@2' task with the 'codeCoverageEnabled' option.

Why A: The 'PublishCodeCoverageResults@1' task is the correct choice because it is specifically designed to publish code coverage results (e.g., Cobertura or JaCoCo XML reports) to Azure DevOps, making them visible in the build summary and pipeline artifacts. This task consumes the coverage data file generated by a previous test run (e.g., via 'DotNetCoreCLI@2' with '--collect "Code Coverage"') and uploads it to the Azure DevOps service for reporting.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This AZ-400 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-400 exam.