Unit test suites are often used as a quality tool during the development process to keep the codebase stable as it changes and expands. Tools such as NUnit, MSTest are often used to run and report on the test suites. However, when implementing unit testing in your build process, you have no way of knowing how much of your code the unit tests are actually testing. This is where code coverage comes in. You can run NUnit, MSTest within the Code Coverage tool and use the report to determine which code was not tested by that test suite.
NCover is the prominent tool but its not free I fount PartCover interesting moreover its free.
Partcover provides 2 style sheets to view the xml report: based on Classes or based on assemblies. Apparently if we have a single Test assembly we should use Class wise report else assembly wise.
Steps to Integrate Partcover into cruisecontrol.net:
Above example is based on Nant build tools, For MSBuild refer below given sample using Exec task:-
<Target Name="PartCover" >
<Exec Command="$(CCNetServer)tools\PartCover.NET4.0\PartCover.exe --settings $(CCNetServer)$(ProjectName)\Factory\partcover\$(projectname).xml --output $(project_artifacts_path)PartCover-results.xml"
Above target is an exerept from my build file where you can see few properties used. Below is the explaination for each property.
1/ PartCover.exe: Command line executable for Partcover.
2/ --settings: argument is case sensitive in build script so use "settings" only. It requires setting.xml file:-
Here + indicates the inclusion and - indecates the excution of a file * acta as wild card notation.
Nunit is one important prerequisite to run this tool. Below is the sample target.
<TestAssembly Include="$(BuildDirectory)MySolution\MyProject\bin\$(Configuration)\MyAssembly.TestNUnit.dll" />
<Target Name="NUnit" Condition="$(Configuration)==debug" >
This will help you to integrate code coverage on your build tool.
More tools and resources on Unit Testing