Geeks With Blogs

News
Employers
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 MyGooglePageRank.com

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 cruisecontrol.net:
http://ccnetlive.thoughtworks.com/ccnet/doc/CCNET/Using%20CruiseControl.NET%20with%20PartCover.html

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"
      ContinueOnError="true"
      WorkingDirectory="$(CCNetServer)tools\PartCover.NET4.0\"
    />
  </Target>

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

<PartCoverSettings>
  <Target>C:\Program Files\NUnit-2.5.3.9345\bin\net-2.0\nunit-console.exe</Target>
  <TargetWorkDir>C:\Program Files\CruiseControl.NET\server\MyProject\WorkingDirectory\MyProject\bin\Debug</TargetWorkDir>
  <TargetArgs>MyAssembly.NUnitTest.dll</TargetArgs>
  <Rule>+[MyAssembly1*]*</Rule>
  <Rule>+[MyAssembly2*]*</Rule>
  <Rule>-[MyAssembly.NUnitTest*]*</Rule>
  <Rule>-[nunit*]*</Rule>
  <Rule>-[log4net*]*</Rule>
</PartCoverSettings>

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.
<ItemGroup>
 <TestAssembly Include="$(BuildDirectory)MySolution\MyProject\bin\$(Configuration)\MyAssembly.TestNUnit.dll" />
</ItemGroup>

<Target Name="NUnit" Condition="$(Configuration)==debug" >
 <NUnit
  ToolPath="$(CCNetServer)tools\NUnit-2.5.3.9345\bin\net-2.0"
  Assemblies="@(TestAssembly)"
  OutputXmlFile="$(project_artifacts_path)NUnit-results.xml"
  ContinueOnError="true"
  WorkingDirectory="$(CCNetServer)tools\NUnit-2.5.3.9345\bin\net-2.0"
 />
</Target>

This will help you to integrate code coverage on your build tool.

More tools and resources on Unit Testing
http://www.testdriven.net/Default.aspx?tabid=27
 

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: GeeksWithBlogs.net