Courseiva

Enforcing an 80% Code Coverage Threshold Without Blocking Passing Tests

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?

⚠ Common exam trap

Some candidates may place 'Publish Code Coverage Results' before 'Visual Studio Test', but coverage results are generated during tests, so they must come after.

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

✓

Visual Studio Build

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).

Answer analysis

Option-by-option breakdown

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

  • ✓

    Visual Studio Build

    Why this is correct

    The Visual Studio Build task invokes MSBuild to compile the solution and must be the first pipeline action because it produces the binary artifacts (e.g., test assemblies, application DLLs, and PDBs) that every downstream task consumes. Both the VSTest task and the Publish Code Coverage Results task depend on this compiled output—VSTest cannot discover or execute tests without assemblies to load, and coverage data is only generated when those tests run. Additionally, MSBuild can perform tasks like restoring NuGet packages and copying build outputs, ensuring that the workspace is in a consistent state before testing begins. Therefore, placing it anywhere other than first would create an immediate hard failure with 'file not found' or 'no test source files' errors.

  • ✗

    Visual Studio Test

    Why it's wrong here

    Visual Studio Test cannot be the first pipeline task because it requires compiled binaries from the build step; the VSTest task executes test assemblies that must already exist, so it has a hard dependency on the build output. Placing it first would fail with 'file not found' or missing test container errors, making it logically the second task after compilation.

  • ✗

    Publish Code Coverage Results

    Why it's wrong here

    Publish Code Coverage Results cannot be the first task because it only consumes coverage data produced during test execution, such as .coverage or Cobertura/ JaCoCo XML files, which do not exist until after tests run. It also requires the build to have generated the binaries under test, so it is dependent on both the build and test tasks, correctly making it the third task in the sequence.

About these practice questions

One of 696 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

3 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 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.

Variation 2. 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 3. 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.

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.