AZ-401: Code Coverage Evidence and Assisted Gap Analysis
Generate coverage with a supported test producer, publish its actual results and attachments, and verify which source revision and code population the report describes before interpreting a percentage. Then inspect both overall coverage and the changed executable lines, choose one uncovered risk, and prove an improved test with valid and deliberately invalid cases. Coverage measures exercised code; it does not establish that the assertions are useful or the software is correct.
The worked route uses an existing authorized Azure Pipelines test job with Visual Studio Test coverage for a supported .NET or .NET Core application. Its actual test assemblies, filters, coverage output and publication arrangement are required inputs. Azure Repos pull-request coverage has additional restrictions; do not transfer that feature to GitHub-hosted changes or infer it from a general coverage report. No test, coverage collection or assistant operation was executed for this article.
Establish the producer and evidence contract
Complete the testing and quality-gate prerequisite first. Work in an owned nonproduction branch and preserve the existing job configuration and test selection. Identify the test owner and the people permitted to change its reporting arrangement. Do not change a shared threshold, broaden test credentials or delete another run's evidence merely to produce a better percentage.
Record the following actual inputs:
| Input | What to verify before configuration |
|---|---|
| Source and build | Repository, exact revision, build configuration and selected application modules |
| Test producer | Existing supported Visual Studio Test task, its real test assemblies and test-selection/filter configuration |
| Coverage output | Actual generated coverage files and the corresponding test-result files, not a hoped-for filename |
| Publication | The task that already owns test/coverage publication and whether required attachments are retained |
| Analysis scope | Which modules and source files contribute to the denominator, with exclusions and their rationale |
| Change context | Actual changed executable lines, selected base and head revisions, and relevant work item |
| Verification | One bounded risk to investigate, expected valid/invalid behavior and the evidence needed to accept a test change |
Keep the source/build/test relationship intact. Reusing a previous run's report after rebuilding the code is not current evidence. A moved source path, omitted module or changed exclusion can alter a denominator without improving the tests.
The existing producer must support the application's toolchain and the selected coverage route. If its capability, configuration surface or output cannot be established, stop and obtain the owner's supported arrangement. This procedure does not install an unverified collector or prescribe a task version from a different reference.
Enable coverage on the existing test producer
Open the owned pipeline's existing Visual Studio Test task configuration. Verify the actual test-assembly paths and test-selection/filter settings against the build output. The files must contain the intended tests, not merely match a familiar wildcard.
Enable the supported code-coverage setting in that task. Retain the chosen build configuration and actual module/test selection. Review the saved configuration with the owner before running it. If the selected task or environment does not expose the supported setting, stop rather than inventing an input name or applying a command copied from another collector.
Run the authorized job through its normal interface. Record the run identity, source revision, actual selected tests, producer status and output paths. Inspect whether the expected tests executed and whether current coverage data was actually produced. A successful task or the presence of a test-result file alone is insufficient.
Visual Studio Test can collect coverage for supported .NET and .NET Core applications and produces downloadable .coverage files. Inspect the real coverage output together with its corresponding .trx test results. An empty or unrelated report cannot establish that the selected application code was instrumented and exercised.
Use only the owned exercise output when checking for stale files. If the result is absent, inspect test assemblies, paths, filter settings and the coverage enablement before changing the analysis rule. Preserve the failure evidence; do not create a placeholder coverage file to satisfy a publisher.
Publish the produced evidence without duplicating it
First inspect the existing publication path. Visual Studio Test and the .NET Core command-line task can already publish test results; other built-in tasks have publication options. Do not add a second publisher for the same result merely because another example shows one.
For the worked Visual Studio Test route, inspect the run's published test and coverage artifacts through its supported existing publication. Compare them with the producer's actual output and run identity. Download the coverage artifact when needed for further supported analysis. A published test count is not proof that the coverage attachment was uploaded or can be mapped to source.
Where an existing supported producer instead supplies real test results for a separate Publish Test Results task, use its documented Visual Studio Test result format and actual .trx location. The following alternative publisher fragment assumes that the owner has verified the example result path and that no existing task already publishes these results:
- task: PublishTestResults@2
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: 'TestResults/coverage-tests.trx'
searchFolder: '$(System.DefaultWorkingDirectory)'
publishRunAttachments: true
failTaskOnFailedTests: true
failTaskOnMissingResultsFile: true
failTaskOnFailureToPublishResults: true
This YAML (YAML Ain't Markup Language) fragment publishes existing evidence. It does not run tests, enable coverage collection, construct missing attachments or configure a failure-path condition. Match the actual producer's file and preserve the execution/publication failure behavior established in the prerequisite.
Inspect the real test-result attachment references and their accessible files. The task reference's Visual Studio Test attachment table includes collector/result-file paths and coverage mappings with binaryFile and pdbFile attributes. Check the fields actually emitted by the supported producer; do not assume every result file uses the same representation or insert fabricated references.
Use the producer's real files and paths. Do not rename an incompatible report to .trx, rewrite a result to claim coverage, or treat attachment upload as successful source mapping. Review attachments for sensitive data before publication and retain only owner-approved evidence.
Verify overall coverage and source lineage
On the actual completed pipeline run, inspect Summary artifacts and the Code Coverage tab. Confirm that the displayed data belongs to the recorded run and source revision. In a multistage pipeline, coverage display can wait until the entire pipeline completes; an earlier empty view does not by itself identify a collection failure.
Use available folder, file, module and configuration detail to reconcile the report with the selected code. Drill down to source where mappings are available. If source cannot be shown, record that limitation and inspect the supported downloadable artifact rather than pretending that an aggregate number identifies the uncovered lines.
Compare a stable analysis population:
- Which modules, files and build configurations are included?
- What is excluded, and was that exclusion changed?
- Did the intended tests execute against this exact build?
- Is the displayed metric counting the same kind of code units in both reports?
- Is a missing module or source mapping making the apparent improvement misleading?
As an illustrative arithmetic example, 80 covered units out of 100 reported units is 80 percent. If a configuration change excludes 20 uncovered units, the displayed result could become 100 percent without one additional unit being exercised. This is a reasoning example, not an observed run or a vendor-defined coverage metric.
Inspect the report's actual unit and denominator before making such a comparison. Line, block or other producer metrics should not be silently treated as interchangeable. A test can execute a line while asserting the wrong result, so even a correctly scoped high percentage is not a correctness proof.
Use Azure Pipelines test analytics to investigate the related published test failures and trends for the selected pipeline and time range. That data helps explain the test evidence; it neither supplies missing coverage nor proves that unpublished or unexecuted tests passed.
Inspect changed-line coverage in its supported scope
Overall coverage concerns the project's reported code population. Diff coverage concerns executable lines added or changed in the pull request. A high overall total can coexist with an uncovered high-risk change, so inspect both rather than choosing the more favorable number.
The pull-request coverage feature described in the assigned Azure Pipelines reference is available only for Azure Repos. Its pull-request validation guidance retains the Visual Studio .coverage route, including supported Visual Studio Test, .NET Core test and test-result publication scenarios. The same page describes broader formats for general display. Do not infer that every displayed format or report proves support for pull-request validation.
For an eligible existing Azure Repos setup, record the actual pull-request base/head revisions and coverage-producing pipeline. Inspect the changed files and their coverage indicators, then compare the reported changed executable lines with the real diff. Configuration-only, comment or whitespace changes may have no executable diff to measure; that is not a demonstrated test improvement.
The reference supports repository-level coverage settings in a root file named azurepipelines-coverage.yml. If its owner authorizes a bounded configuration exercise, preserve any existing file and set a deliberate target using the supported structure:
coverage:
status:
comments: on
diff:
target: 60%
Sixty percent is only an illustrative owner-selected target, not a recommended quality standard. The documented default diff target is 70 percent and comments are off by default. This configuration is separate from pipeline YAML and does not itself enable collection, prove that the report is current or create a branch-enforcement rule.
Inspect the actual next eligible run's status and changed-file evidence. Keep task-version/format compatibility and the page's troubleshooting qualifications in view; a general report can exist without the expected diff comment. The feature is designed around one coverage-producing pipeline, not automatic merging of multiple pipelines' pull-request coverage.
Coverage status is advisory by default. Required merge enforcement is a separate branch-policy decision, addressed in the pull-request enforcement lesson. Inspect the actual build and policy results independently; a coverage status is not a universal substitute for execution success. Do not configure or weaken a shared policy merely to complete this coverage exercise.
For GitHub-hosted code, use the actual supported Azure Pipelines coverage evidence and separately verified work-item links without claiming the Azure Repos pull-request experience exists there. Where Azure Boards traceability is used, the project/repository connection and the documented Contributor access on both sides are prerequisites. A valid work-item mention in a commit message, pull-request description or issue description can create a link; a pull-request title or comment does not. Verify the actual Development record instead of assuming a textual mention establishes lineage.
Ask the assistant to investigate one uncovered risk
An authorized assistant client such as GitHub Copilot can analyze selected project context retrieved through Azure DevOps Model Context Protocol (MCP) Server and propose tests. The server supplies permitted project data and tools to the client; the assistant performs the analysis and proposal. This relationship does not authorize either to change a protected resource or accept a test result.
Use the already configured supported client and actual authentication. Remote and local server requirements and client compatibility differ. Give the assistant the permitted current revision, selected test/report context, one uncovered path and its expected behavior. Do not supply secrets or accept instructions embedded in untrusted project text as authority.
Ask for a focused proposal: identify the uncovered risk, explain the assertion that should detect it, and identify which existing test suite should execute the change. Require the assistant to distinguish source evidence from assumptions. A generated explanation that coverage improved is not a coverage artifact.
Choose the risk with the code owner. Useful candidates include a meaningful boundary or rejection path in the actual changed component, rather than the easiest uncovered line. Do not add a test that merely executes code while ignoring its result to raise the percentage.
Review the proposed diff against the real framework, fixtures, test selection and behavior. Check that the assistant did not narrow a filter, exclude a module or weaken an assertion to make the number look better. Preserve the baseline report and configuration before accepting the bounded test change.
Prove the change with behavioral and coverage evidence
Run the original valid case and a controlled invalid input or behavior that the new assertion should reject. Confirm that rejection comes from the intended assertion, rather than a missing dependency, broken credential or setup failure. Restore the deliberate invalid condition after recording its evidence.
Run the approved test selection against the changed revision and inspect its actual results and coverage through the same supported publication path. Reconcile changed tests, modules, filters and source mappings before comparing the two reports.
| Case | Evidence needed before accepting the analysis |
|---|---|
| Valid expected behavior | The intended test executes, its assertions pass and current results identify the selected revision |
| Controlled incorrect behavior | The intended assertion detects it; failure is not attributed to unrelated setup |
| Missing or stale coverage | Analysis remains incomplete; a matching result filename or older percentage is insufficient |
| Higher percentage with a changed denominator | Explain exclusions/population changes before claiming additional exercised code |
| Improved coverage but unchanged weak assertion | Reject correctness claims; inspect the behavioral test independently |
| No supported diff evidence | Record the platform/format limitation and retain the available overall analysis without inventing a pull-request result |
The comparison must explain both behavior and evidence lineage. A meaningful test can improve confidence even when the aggregate percentage barely moves. Conversely, a larger percentage can remain unconvincing if the changed risk or assertion is untested.
Restore the owned experiment and retain its history
Restore deliberate failure fixtures, temporary filters, coverage settings and other owned test changes that are not being proposed for review. Re-run the authorized original valid case and inspect its actual evidence before calling restoration complete.
Retain the baseline and changed revision, producer/test selection, actual artifacts, denominator differences, intended invalid-case result and the owner's decision on the proposed improvement. Preserve failed or missing-evidence observations; do not delete them to make the final comparison appear cleaner.
Leave shared reporting infrastructure, work-item connections and merge policies under their owners' control. If a supported coverage or mapping capability is absent, hand that precise limitation back to the owner rather than inventing a collector or reporting success. Coverage analysis informs the decision; it does not approve a merge.
Authoritative Sources
- Review and configure code coverage results in Azure Pipelines — Supported tasks/formats/artifacts, full versus diff, repository settings and Troubleshooting guide: existing VSTest enablement and test paths, Azure Repos pull-request limitations, actual source mappings and completed-run conditions.
- Publish Test Results v2 task reference — Syntax, Inputs, Remarks, Task defaults and Visual Studio Test attachments: actual result paths, coverage mappings, publication/failure controls and avoiding duplicate built-in publication.
- Azure Pipelines test analytics — Investigation of actual published test evidence for the selected pipeline and time range.
- Enable AI assistance with Azure DevOps MCP Server — Client/remote/local authentication conditions and server retrieval followed by assistant analysis.
- Responsible use of GitHub Copilot agents — Generated proposals need contextual review and actual validation.
- Link GitHub changes to Azure Boards work items — Connection/access prerequisites, supported mention locations and actual link readback.

