Publishing test results
This option&; is valid only
if we have the Team explorer installed, and if the Visual Studio is
connected to the Team Foundation Server (TFS). This publishes the test
data and results to the TFS team project. Please refer to MSDN for more
information on installing and configuring TFS and Team explorer.
Using the command line utility and the various options, we can publish the test run results. The publish option with MSTest
will first run the test and then set the flavor and platform for the
test before publishing the data to the TFS. Some of these options are
mandatory for publishing the test run details.
We will see the examples of different publishing options available for the command line MSTest tool.
/publish
The /publis&;h
command should be followed by the URI of the TFS if the TFS is not
registered in the client. If it is registered, we can use just the name
of the server to which the test result has to be published.
Example 1: /publish:http://MyTFSServer
(If the TFS Server is not registered in the client)
Example 2: /publish:MyTFSServer
(If the TFS Server is registered with the client)
/publishbuild
This option&; is
used for specifying the build name for publishing. This is the unique
name that identifies the build from the list of scheduled builds.
/flavor
This is a m&;andatory
option for publishing the test results to the TFS. Flavor is a string
value which should be used in combination with the platform name and
should match with the completed build that can be identified by the /publishbuild option. Before publishing the test run results to the TFS, MSTest will run the test and then set the flavor and the platform properties.
Examples 1: /flavor:Release
Example 2: /flavor:Debug
/platform
This is a m&;andatory string value used in combination with the /flavor option which should match the build option.
Example 1: /platform:Mixed Platforms
Example 1: /platform:.NET
Example 1: /platform:Win32
/publishresultsfile
MSTest stor&;es all test results in default trace files with the extension .trx. Using this /publishresultsfile option we can publish the test results output/trace file to the TFS. The name of the file is the input to this option. If the value is not specified, MSTest will publish the current test run trace file to TFS.
/publishresultfile:[file name string]
Example 1: /publishresultfile
(current test run trace file will be published)
Example 2: /publishresultfile:
Trace files
Before publ&;ishing the test result we have to store the test results in a trace file. Use the /tracefile option with the MSTest
command line to store the test results. The default extension for the
trace file is trx. It is better to use the same extension when we force
the Visual Studio to use a specific trace file for the test results.
For example:
MSTest /testmetadata:TestProject.vsmdi /testfile:TestProject.trx
Publishing
To publish the test result, we can use a combination of the different options seen above, and the only option is /publishresultsfile.
Let us try creating a trace
file and then create a build type for the project. Then we can publish
the test result trace file to the build.
Step 1: Create test project
The followi&;ng image contains the solution ClassLibrary1. The solution contains a simple class library project ClassLibrary1. Use the menu option, Test | New Test
from the Visual Studio IDE and then choose the unit test type. Name the
test and select the existing project or choose the option to create a
new project to add the new test. The following image shows the test
project named ClassLibrary1TestProject.
Step 2: Running the test
The test pro&;ject ClassLibrary1TestProject contains two unit test methods. Run the test and by default, the test result is stored in the trace files<file name>.trx.
Step 3: Create Build
Now is the ti&;me to
create the build type for the team project. The steps and the details
behind creating the build types are out of the scope of this book. So
let us do an overview on how to create the build type using the Team
Explorer. Within the Team Explorer, select the Build definitions under the Builds
option folder, which is under the team project. Right-click and choose a
new build definition and configure the options by choosing the projects
in TFS and the local folder. In one of the steps, you can see the
following screenshot for selecting the project and setting the
configuration information for the build.
The following
scree&;nshot shows the important configuration setting required for
build, which should match the test results publishing parameters: the
platform and the flavor values:
Step 4: Build Project
Now we have cre&;ated all
the projects and set the configurations and properties. We are ready to
run the test, build and publish the test results. Select the new build
and run it. You can notice the Build name for the current build. The Build steps
show the platform and the flavor used for building the solution. The
result details section shows no test results as we do not have any test
results published yet.
Step 5: Publish Result
So far we have c&;reated
the test results file and also built the projects. All the test runs
were successful in which the test failed. Now is the time to publish the
test results to the build. We have seen the options used for publishing
the test results using the MSTest command line. The following command
publishes the two test results to the build specified:
The command line options used
in the above picture shows the test result trace file used for
publishing. The command line also has the platform and the flavor values
matching the build configurations set in step 3 above. The publishing
is done using the web service shown previously. There are different
methods exposed by the web service.
After publishing&; the test results, if you open the build NewBuild_20081029.2, you can see the test information as shown in the following image, which is nothing but information from the trace file.
The
test URL will open the page which shows all the details of the test run.
You can publish any number of test results to the TFS and bind it to a
particular build so that the test results correspond to that particular
build.