dotCover with MSBuild and MSTest

Hello guys,

The company I work for, owns TeamCity Enterprise Edition with dotCover build in.
We are trying to have code coverage with dotCover, but couldn't make it work.
The configuration is following:
I'm using MSBuild script file to run MSTest executable agains multiple test dll's each of them has appropriate .testrunconfig file and test category specified. (Using MSBuild <Exec> task)

<?xml version="1.0" encoding="utf-8" ?>
<!--=======================================================================================
  MSBuild file that invokes mstest on all projects with ".Tests" suffix. 
  Created by Greg MacLellan, Dec 1 2010
===========================================================================================-->
<Project ToolsVersion="4.0"
           DefaultTarget="RunUnitTests"
           xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <MsTestExePath Condition="'$(MsTestExePath)'==''">C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe</MsTestExePath>
  </PropertyGroup>

  <ItemGroup>
    <TestAssemblies Include="$(<Some assemblies>).dll" />
  </ItemGroup>

  <Target Name="RunUnitTests">
    <Message Text="Found test assemblies: @(TestAssemblies)" />
    <MakeDir Directories="$(<some folder>)\TestResults" />
    <CallTarget Targets="RunMsTest" />
  </Target>

  <!-- For reference, the key to making this work is the Outputs="" parameter on the Target 
       RunMsTest target runs MSTest against the DLLs in TestAssemblies 
        -->
  <Target Name="RunMsTest" Outputs="%(TestAssemblies.Filename)">
    <Message Text="Running tests in %(TestAssemblies.Filename)%(TestAssemblies.Extension)" />
    <!-- show TC progress -->
    <Message Text="##teamcity[progressMessage 'Running tests in %(TestAssemblies.Filename)']" Importance="High" />

    <PropertyGroup>
      <MsTestCommand>"$(MsTestExePath)" /testcontainer:"%(TestAssemblies.FullPath)" /runconfig:%(TestAssemblies.RootDir)%(TestAssemblies.Directory)%(TestAssemblies.Filename).testrunconfig /category:"UnitTests" /resultsfile:"$(<some folder>)\TestResults\%(TestAssemblies.Filename).trx" </MsTestCommand>
    </PropertyGroup>
    <!-- Message Text="Exec: $(MsTestCommand)" / -->
    <Exec Command="$(MsTestCommand)" ContinueOnError="true" />

    <!-- import data to teamcity test results -->
    <Message Text="##teamcity[importData type='mstest' path='$(<some folder>)\TestResults\%(TestAssemblies.Filename).trx']" />

    <Message Text="Tests complete from %(TestAssemblies.Filename)%(TestAssemblies.Extension)" />
  </Target>

</Project>

My question is: How can I make dotCover analyse these assemblies and how to make TeamCity report them?

Cheers,

Please sign in to leave a comment.