Tim Huffam

Dotting the I and crossing the T of I.T.

  Home  |   Contact  |   Syndication    |   Login
  153 Posts | 0 Stories | 2415 Comments | 653 Trackbacks

News

Archives

Post Categories

Interesting Blogs/Links

Tuesday, June 16, 2009 #

This requires a testrunconfig file that has been configured correctly.  To do this I did the following:

  1. In VS2008, right click on Solution Items folder and select Add - New Item...
  2. Select Test Run Configuration and enter the name WithCodeCoverage.testrunconfig.
  3. Open/edit this file in VS.
  4. Select the 'Code Coverage' item on the left, then selected (checked) the assemblies I wanted to instrument
  5. Click Apply to save these changes.

Note that you can select which is the active test run configuration from under the Test menu in VS2008.

Now we need to update the TFS build...

  1. Open your TFS build file (eg TFSBuild.proj)
  2. In the section starting with
    <PropertyGroup>
    <!--
    TEST ARGUMENTS...
    Add the following line (after the comments and before the closing of PropertyGroup):
    <RunConfigFile Condition=" '$(IsDesktopBuild)' != 'true' ">$(SolutionRoot)\DEV\Release1\Source\WithCodeCoverage.testrunconfig</RunConfigFile>
    (update accordingly to suit your build server paths).

That's it.  Queue a build to test - you may need to verify your server build paths to get it working (I did).

HTH
Tim


The following will make your builds (running on a TFS Server) execute your unit tests after the build:

  1. Open your build file (eg TFSBuild.proj).  VS2008 has a nice xml editor for this.
  2. Search for the RunTest node and change it from:
    <RunTest>false</RunTest>
    to:
    <RunTest>true</RunTest>
  3. Look for a section that starts with:
    <ItemGroup>
    <!--
    TEST ARGUMENTS ...
    and add nodes within this (after the comments and before the closing of the ItemGroup node) - one entry for each unit test assembly you have eg:
    <TestContainer Include="$(OutDir)\My.App.UnitTests.dll" />

Thats it - check in this file and queue a build.

An error I got while getting this working indicated that the MSTest.exe could not be found - this was because TFS Client had not been installed on the build server - once these were installed it worked fine.

Something else you may want to do is ensure that a build is triggered every time someone checks in.  To do this, edit your build definition (right click on your build within Team Explorer and choose "Edit Build Definition...") - click on the 'Trigger' item in the list on the left and make sure the "Build each check-in (more builds)" item is checked.

HTH
Tim