How to Publish Test Results to the UI in Azure Pipelines
The PublishTestResults@2 task surfaces JUnit/xUnit results in the Azure Pipelines Tests tab.
Run tests so they emit a JUnit (or xUnit/VSTest) XML file, then publish it with PublishTestResults@2. Set condition: always() so results show even when tests fail.
Publish JUnit results
The publish step runs even on failure, so the Tests tab shows which tests failed.
azure-pipelines.yml
steps:
- script: npm ci && npm test -- --reporters=jest-junit
displayName: Run tests
- task: PublishTestResults@2
condition: always()
inputs:
testResultsFormat: JUnit
testResultsFiles: '**/junit.xml'
failTaskOnFailedTests: trueGotchas
- Set
condition: always()or the publish step is skipped when tests fail - exactly when you most want the report. - Match
testResultsFormatto your reporter (JUnit,xUnit,VSTest,cTest) or the file is ignored. failTaskOnFailedTests: truemakes the publish task itself fail the job on any failed test, useful as a backstop.
Related guides
How to Show Test Results in the UI in Bitbucket PipelinesSurface test results in the Bitbucket Pipelines UI by writing JUnit XML to test-results/ where Bitbucket auto…
How to Publish a Coverage Report in Azure PipelinesPublish a code-coverage report in Azure Pipelines with the PublishCodeCoverageResults task, rendering Cobertu…