Vlad"s Software Development Toolbox

Sunday, 22 March 2009

Integrating PartCover with Visual Studio 2005

To help myself with developing unit tests and have a control over which parts of the code get executed I decided to add code coverage tool to a collection of Third-party tools. I looked at NCover, TestDriven.Net and PartCover. My choice is stopped on PartCover. This is an open source code converge tool and very much similar to NCover. I missed the ability to run it directly from Visual Studio like TestDriven.Net runs NCover so I looked around and found a way of integrating it into Visual Studio 2005. Unfortunately there is no way of running PartCover code explorer along with PartCover report generator and NUnit in the single command so I had to write PartCover.cmd batch script to combine execution of these tools. Below is a sample content of that file. If you are using EnvMan source code please check out PartCover from ThirdParty in SNV.


REM === Start PartCover.cmd ===
"C:\Path\To\PartCover\partcover.exe"--target "C:\Path\To\NUnit\nunit-console.exe"--target-work-dir %1 --target-args %2 --output %1\partcover.xml --include %3

"C:\Path\To\PartCover\PartCover.Browser.exe" %1\partcover.xml
REM === End PartCover.cmd ===

Integrating PartCover with Visual Studio 2005

To integrate PartCover with Visual Studio select menu Tools\External Tools ...
In the External Tools Dialog box click Add and enter the following data in the fields.


Part Cover




[*Assembly Regular Expression*]*

Initial Directory:


Tick Use output Window and Prompt for Arguments. Click OK

Running PartCover

To run PartCover select EnvManTest project and use Part Cover from Tools menu. Because we ticked "Prompt for Arguments" the following dialog box appears.

Replace "Assembly Regular Expression" with "EnvMan" so it looks like this [*EnvMan*]*. Please look at PartCover documentation for more details about regular expressions. After OK is clicked output window of Visual Studio will show a progress of the coverage test and Part Cover Code Browser window will appear. At the moment it will not show any code until we open generated partcover.xml report file.


Nils said...

Hi. Starting the Browser as you suggested does is not supported with the current version of partcover. See partcover feature request #2445978. Any other Ideas?

Vlad said...

I created a new post that covers new version of the PartCover Browser.

Creating project code coverage with PartCover and NUnit