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.
PartCover.cmd
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 ...![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSa1iGOSwnz9VKsbz1hygizk3EnWtDxThnP6yFTDt0gFV5WXeuy8WdcamfxowTOijunIuZ0uZ4hgFxg0XTSw5VYsUg491c2eGcmXZhToaSdfZoaK82NEw1XapDpALTnLg1NWf9ppAVViDA/s400/PartCoverVS1.png)
Title: |
Part Cover |
Command: |
C:\Path\To\PartCover\PartCover.cmd |
Arguments: |
$(ProjectDir)\bin\Debug
|
Initial Directory: |
$(ProjectDir)\bin\Debug |
Tick Use output Window and Prompt for Arguments. Click OK
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr0pP2LNdYSTDgFYOqG1lqHeD8lEsckjJ58ZZEKaImhXEZjA9-5gjLbZBAmuxE8GW46zyvqmTTNC_eUuJeWK1ML5wgeY_aWiD9yEbhBEdHSYUILK9VTSzMsrmjla6oW-nxiTL4jSizfY6a/s400/ExternalTools.jpg)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvYRZcZOwRFm5tQ5jsNZso0v1XYnA6yoXQwsZ7od5y6xPGqaBDIdYEfz-CYTVtn-LdR-Lxk5XCMW58lflOyXXoJmif5QQFH2tgLZuzPXAkmgRQ9_bsfaMBxrIMJOCtoDzxtVjwf_r6CmPo/s400/PartCover.jpg)
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.