TFS, MSBuild and Code Coverage
April 28, 2008
When you have a testing framework in place you of course want to test it each build. But of course, you also want to know much code your tests are covering, a.k.a. CodeCoverage.
It is in a way quite easy to accomplish in your build script. The only catch is the complete lack of documentation. Benjamin Day led the way (he he - it rhymes).
What you need to do is two things:
-
First configure the tests to run. This is easily done by adhering to good naming standards (all test assemblies ending with tests.dll). Then you can add create an item group called TestContainer, like below. This will run through all your tests.
<ItemGroup> <TestContainer Include="$(OutDir)\%2aTests.dll" /> </ItemGroup> -
Secondly (and here is the secret) you need to specify that the tests are to be run under code coverage....