Geeks With Blogs

Soppa Group India
iSmart Panache Inc
R Systems Internationals Ltd
Technovate eSolutions Pvt Ltd
The contents of this blog are my personal opinion and do not represent in any way the view of my employer.
These postings are provided "AS IS" with no warranties, and confer no rights.

Google PR™ - Post your Page Rank with

Narendra Tiwari

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

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:-

  <Target>C:\Program Files\NUnit-\bin\net-2.0\nunit-console.exe</Target>
  <TargetWorkDir>C:\Program Files\CruiseControl.NET\server\MyProject\WorkingDirectory\MyProject\bin\Debug</TargetWorkDir>

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

Posted on Friday, July 16, 2010 12:43 PM .Net | Back to top

Comments on this post: Code Coverage using PartCover in MSBuild

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Narendra Tiwari | Powered by: