Lesson328 words

Implementing tests in a pipeline

Implement tests in a pipeline

Publish result files when the runner does not

A raw script or runner can leave supported test-result files without sending them to Azure Pipelines. In that case, a separate PublishTestResults@2 step makes the results visible in the Tests tab and available to Test Analytics. Built-in tasks such as Visual Studio Test and .NET Core CLI can publish automatically, and several other tasks expose integrated publication, so they do not need a duplicate publish step.

yaml
- task: PublishTestResults@2 inputs: testResultsFormat: 'JUnit' # JUnit | NUnit | VSTest | xUnit | CTest testResultsFiles: '**/TEST-*.xml' mergeTestResults: true condition: succeededOrFailed()

Two details that matter:

  • condition: succeededOrFailed() — use it on a separate publisher that must run after an earlier failure in a non-cancelled run. The default step behavior runs only while nothing in the job has failed. Use always() if the publisher must also run after cancellation.
  • Multiple formats are supported: JUnit, NUnit, VSTest, xUnit, CTest. The format must match what the test runner emits.
  • mergeTestResults: true combines files into one run. More than 100 result files are merged even when this input is false.

Test agents and parallelism

Distributing tests across agents can cut wall-clock time. Each agent runs one job at a time, so parallel testing requires multiple agents, sufficient parallel-job capacity, strategy: parallel, and slices that can run independently. Use the supplied slice-position variables so failures can be reproduced against the same partition.

Results as a gate

Publication and enforcement are separate. Published results feed the Tests tab and Test Analytics. The test command can fail the job itself, or a standalone publisher can use failTaskOnFailedTests: true because its default is false. A branch build-validation policy then evaluates the pipeline's build result to decide whether the pull request can complete; it does not directly query Test Analytics.

Primary sources

Ready to study Designing and Implementing Microsoft DevOps Solutions (AZ-400)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free