Skip to content
Latchkey

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: true

Gotchas

  • Set condition: always() or the publish step is skipped when tests fail - exactly when you most want the report.
  • Match testResultsFormat to your reporter (JUnit, xUnit, VSTest, cTest) or the file is ignored.
  • failTaskOnFailedTests: true makes the publish task itself fail the job on any failed test, useful as a backstop.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →