How to: Obtain Command-Line Test Results

You use the executable program MSTest.exe to run tests from a command line. MSTest.exe automatically displays a run summary to the command prompt window.

It also automatically saves test results to disk. In the Summary section of the results output screen, MSTest displays the name of the automatically generated results file. For example:

Results file: D:\temp\test\TestProject3\TestProject3\TestResults\thisuser@ThisUser-32G 9_24_2005 1_27_37 PM.trx

If you prefer, you can explicitly save test results to a file that you name. And if your Visual Studio client session is connected to a Team Foundation Server, you can publish results to your team's operational store. Both of these options are described in the following procedures.


For information about publishing test data from Visual Studio, see How to: Publish Test Results.

To save command-line test results to a specific file

  • Using the MSTest program, run tests.

    Use the /resultsfile:[file name] option to specify the name of a file in which you want to save test results. For example:

    MSTest /testmetadata:Bank.vsmdi /resultsfile:BanktestResults.trx


    Test results files need the .trx extension to function properly, but the MSTest command does not automatically supply that extension. Therefore, we recommend that you include the .trx extension when you run this command.

    For more information on the options you can use with the MSTest program, see MSTest.exe Command-Line Options.

To publish command-line test results to the operational store

  • Using the MSTest program, run tests.


    You can publish test results to the operational store only if connected to a Team Foundation Server and if you have Team Explorer installed. For information about connecting to Team Foundation Server, see How to: Connect to Team Foundation Server.

    Several command-line options pertain to publishing test results. You use them in combination, depending on which test results you want to publish. Five of these options are required: /publish, /publishbuild, /teamproject, /platform, and /flavor. One is optional**: /publishresultsfile**.

    • Publish current test results. To run tests and publish their results immediately, use options that specify the tests to run and the required options for publishing. For example:

      MSTest /testcontainer:test.dll /publish:http://ourtfsmachine:8080 /teamproject:ProjectName /publishbuild:BuildNumber01 /platform:AnyCpu /flavor:Release

    • Publish past test results. To publish the results of tests that were run previously, omit any command-line options that specify tests to run -- such as /testcontainer: and /testmetadata:, because you are not running tests. For example:

      MSTest /publishresultsfile:testResult.trx /publish:http://ourtfsmachine:8080 /teamproject:ProjectName /publishbuild:BuildNumber01 /platform:AnyCpu /flavor:Release

      For more information on using these options, see MSTest.exe Command-Line Options.

See Also


How to: Run Tests from the Command Line

How to: Publish Test Results

How to: Connect to Team Foundation Server


Publishing Test Results

MSTest.exe Command-Line Options