Test: Publish Test Results

VSTS | TFS 2018 | TFS 2017 | TFS 2015

Note

Build and release pipelines are called definitions in TFS 2018 and in older versions. Service connections are called service endpoints in TFS 2018 and in older versions.

icon Publishes the test results to TFS or VSTS when tests are run using a runner of your choice.

The task supports popular test result formats including JUnit, NUnit 2, NUnit 3, Visual Studio Test (TRX), and xUnit 2. If you use the built-in tasks such as Visual Studio Test to run tests, results are automatically published and you do not need a separate publish test results task.

Demands

The build agent must have the following capabilities:

  • MSBuild
  • Azure PowerShell

YAML snippet

# Publish Test Results
# Publish Test Results to VSTS/TFS
- task: PublishTestResults@2
  inputs:
    #testRunner: 'JUnit' # Options: jUnit, nUnit, vSTest, xUnit
    #testResultsFiles: '**/TEST-*.xml' 
    #searchFolder: '$(System.DefaultWorkingDirectory)' # Optional
    #mergeTestResults: false # Optional
    #testRunTitle: # Optional
    #platform: # Optional
    #configuration: # Optional
    #publishRunAttachments: true # Optional

Arguments

Argument Description
Test result format Specify the format of the results files you want to publish. The following formats are supported.
- Version 1 of the task: JUnit, xUnit 2, NUnit 2, Visual Studio Test Results (TRX)
- Version 2 of the task: JUnit, xUnit 2, NUnit 2, NUnit 3, Visual Studio Test Results (TRX)
Test results files Use this to specify one or more test results files.
- Version 1 of the task: You can use a single-folder wildcard (*) and recursive wildcards (**). For example, **/TEST-*.xml searches for all the XML files whose names start with TEST- in all subdirectories. Multiple paths can be specified, separated by a semicolon.
- Version 2 of the task: Also accepts minimatch patterns. For example, !TEST[1-3].xml excludes files named TEST1.xml, TEST2.xml, or TEST3.xml.
Search folder Available only in version 2 of the task. Folder to search for the test result files. Default is $(System.DefaultWorkingDirectory)
Merge test results When this option is selected, test results from all the files will be reported against a single test run. If this option is not selected, a separate test run will be created for each test result file.
Test run title Use this option to provide a name for the test run against which the results will be reported. Variable names declared in the build or release process can be used.
Advanced - Platform Build platform against which the test run should be reported. For example, x64 or x86. If you have defined a variable for the platform in your build task, use that here.
Advanced - Configuration Build configuration against which the Test Run should be reported. For example, Debug or Release. If you have defined a variable for configuration in your build task, use that here.
Advanced - Upload test results files When selected, the task will upload all the test result files as attachments to the test run.
Control options See Control options

More Information

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

I use TFS on-premises and I don't see some of these features. Why not?

Some of these features are available only on VSTS and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.

Help and support