This project is read-only.

TFS 2010 Integration Tutorial

Please note that this tutorial requires a build later than the currently published StatLight v1.6 release of Tue Dec 20 2011. You should first download the latest available build from team city. After you click on the link select the guest account to login and then download the artifacts for the latest successful build.

Download the latest StatLight build from here


This tutorial documents one way that StatLight can be used with TFS 2010. It assumes that you are familiar with editing TFS build definitions and build templates. If you aren’t you should first learn how to do this before proceeding.

Create a build process template

  • Create a copy of the ‘DefaultTemplate’ build process template and name it ‘StatLightTestsTemplate’.
  • Add and commit the new file to your repository so that it will be available on the server for a build.
  • Open the ‘StatLightTestsTemplate’ for editing.
  • We will only be working with the ‘Run On Agent’ scoped activity so to simplify the start point click on the ‘Collapse All’ option available in the top right hand corner of the design surface.

Editing the new template

Double-click on the ‘Run on Agent’ activity.

Double-click on the ‘Try Compile, Test, and Associate Changesets and Work Items’ activity.

Double-click on the ‘Sequence’ activity.

Double-click on the ‘Compile, Test, and Associate Changesets and Work Items’ activity.

Double-click on the ‘Try Compile and Test’ activity.

Double-click on the ‘Compile and Test’ activity.

Double-click on the ‘For Each Configuration in BuildSettings.PlatformConfigurations’ activity.

Information: For the test results produced by StatLight to be correctly published and associated with the build that produced them we need to know which ‘platform’ and ‘configuration’ was used. This information is available from the variable ‘platformConfiguration’ defined in the ‘Foreach’ of the activity. As it is scoped at this level it is available to us for use in the child activities.

Double-click on the ‘Compile and Test for Configuration' activity.

Information: To honour the ‘Disable Tests’ value that can be set for a build definition we will be performing our test run as a child sequence of the ‘If not DisableTests’ activity.

Double-click on the ‘If not DisableTests’ activity.

Double-click on the ‘Run Tests’ activity.

This will open the ‘Run Tests’ sequence activity where we can perform our automated testing using StatLight.

Add a new Sequence activity after the ‘If Not TestSpecs is Nothing’ activity and name it ‘Run StatLight Tests’. The ‘Sequence’ activity is available in the ‘Control Flow’ tab of your ToolBox.

Next we need to add a variable for the test results name. Click on the ‘Run StatLight Tests’ activity to select it and then click on the Variables tab if is not visible.

Click on ‘Create Variable’ and create one as follows:

Name: StatLightTestResultsFileName
Variable type: String
Scope: Run Tests
TestResultsDirectory + "\StatLightTestResults_" + BuildDetail.TeamProject.Replace(" ", String.Empty) + "_" + platformConfiguration.Platform.Replace(" ", "") + "_" + platformConfiguration.Configuration.Replace(" ", "") + ".trx"

Information: The value defined will produce a unique file for the test run results with the team project, platform, and configuration provided by the current build process. The 'TestResultsDirectory’ value is a default template variable defined for the ‘Run On Agent’ activity. The ‘BuildDetail’ value is a default template variable defined for the root ‘Sequence’ activity. The platformConfiguration value is a variable defined in the ‘For Each Configuration in BuildSettings.PlatformConfigurations’ activity.

Once the variable has been created click on the ‘Run StatLights Tests’ activity to ensure it is selected.

Add two ‘InvokeProcess’ and one ‘SetBuildProperties’ activities to the sequence. These activity types are available in the ‘Team Foundation Build Activities’ tab of your ToolBox. Name them as ‘Perform StatLight Test Run’, ‘Publish Test Results ‘, and ‘Set Build Test Status’ respectively.

Click on the ‘Perform StatLight Test Run’ activity and edit its properties.

Set the ‘FileName’ as the location where StatLight is available.

Information: StatLight will need to be available on each build controller that is used to process tests under its control. You should make this available from a directory that can be used to organise all tools and resources that you wish to make available for your build processes.

Set the ‘Arguments ‘ as follows:
"-x=""" + BinariesDirectory + "\MyTests.xap"" --ReportOutputFileType=TRX -r=""" + StatLightTestResultsFileName + """ "

Information: Replace ‘MyTests.xap’ with the name of the xap file that should be processed. The ' BinariesDirectory’ value is a default template variable defined for the ‘Run On Agent’ activity. The ‘StatLightTestResultsFileName’ value is the variable we created for the ‘Run StatLight Tests’ activity.

Click on the ‘Publish Test Results’ activity and edit its properties.

Set the ‘FileName’ as the location where MsTest is available.

Information: While an MSTest activity is available from the ToolBox it will not serve our purposes as it expects to be provided with a Test Container or , neither of which are available to us in this case.

Set the ‘Arguments ‘ as follows (include the leading and ending quotes):

"/nologo /usestderr /publishresultsfile:""" + StatLightTestResultsFileName + """ /publish:""" + BuildDetail.BuildServer.TeamProjectCollection.Name + """ /teamproject:""" + BuildDetail.TeamProject + """ /publishbuild:""" + BuildDetail.Uri.ToString + """ /platform:""" + platformConfiguration.Platform + """ /flavor:""" + platformConfiguration.Configuration + """ "

Information: The arguments should be presented in the expression editor as a single line.

Click on the ‘Set Build Test Status’ activity and edit its properties.

Set the ‘PropertiesToSet’ value as ‘Test Status’.

Set the ‘Test Status’ value (available at the bottom of the grid) to ‘Succeeded’.

Save your new template and check it in to your repository.

Create a new build definition

  • In Team Explorer right-click on the 'Builds' node and select 'New Build Definition'.
  • Set the ‘Build Process Template’ for the build definition as ‘StatLightTestsTemplate’.
  • Set the definition parameters for your project.
  • In the Agent Settings set the MSBuild Platform as x86. This addresses a known issue for building components that target assemblies from the Silverlight SDK in 64-bit environments.
  • Now run your build. When complete your test results will have been stored in the TFS database and will be downloaded and presented in the Test Run dialog when you click on the ‘View Test Results’ link.

Last edited Jul 30, 2012 at 9:27 PM by Trev72, version 5


No comments yet.