AZ-400 exam dumps

AZ-400 practice question 122 of 306

Designing and Implementing Microsoft DevOps Solutions. Professional level, Microsoft. Free question with the correct answer and a full explanation.

AZ-400 Question 122

Single answer

You are configuring an Azure DevOps pipeline for a .NET 6 project that uses MSTest for unit testing. The team wants to measure and display code coverage results in the pipeline summary. Which approach should you implement to collect and publish code coverage results?

  1. A

    Use a separate container image that generates HTML coverage reports, then upload the reports as build artifacts.

  2. B

    Add a 'dotnet test' task with code coverage parameters (e.g., /p:CollectCoverage=true, /p:CoverletOutputFormat=cobertura) followed by a 'Publish Code Coverage Results' task referencing the cobertura output.

  3. C

    Write a custom script to run a third-party coverage tool locally, then manually push the generated files to a Git repository for future reference.

  4. D

    Include only a 'Publish Test Results' task in your pipeline, trusting it to automatically detect and upload coverage data.

Show answer and explanation

Correct answer: B

Explanation

To implement code coverage analysis in Azure DevOps for a .NET project, you typically run your tests with coverage enabled (for example, using Coverlet via the 'dotnet test' command) and then publish the coverage data using the 'Publish Code Coverage Results' task. This allows Azure DevOps to parse and display coverage metrics in the pipeline summary. Refer to Microsoft's official documentation (docs.microsoft.com/azure/devops/pipelines/tasks/test/publish-code-coverage-results) for more details on configuring the task properly.

  • A. Incorrect.

    Incorrect. Simply generating HTML reports in a separate container and uploading them as artifacts does not integrate code coverage results into the Azure DevOps pipeline summary.

  • B. Correct.

    Correct. Using the 'dotnet test' command with the appropriate coverage parameters and then running the 'Publish Code Coverage Results' task is the recommended approach to capture and display coverage information in Azure DevOps.

  • C. Incorrect.

    Incorrect. While you could run third-party tools locally, this approach is cumbersome and does not automatically display coverage data in the Azure DevOps UI. The preferred method is to generate and publish coverage data within the pipeline itself.

  • D. Incorrect.

    Incorrect. The 'Publish Test Results' task only publishes test result files (e.g., TRX). It does not publish code coverage data unless you specifically include a step to collect and publish code coverage results.

Timed practice exam

Take a AZ-400 practice test under exam conditions

70 questions in 90 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam