.NET, ReportGenerator, Test
Just some days ago, a new code coverage tool was released for the first time. It's called OpenCover. Shaun Wilde created this tool, since PartCover 4 has some issues that are difficult to resolve with the current code base. He describes some of them on his blog.
In this post I will do a comparison between OpenCover and PartCover and show how these tools can be used to get the coverage of unit tests.
OpenCover runs on 32/64 Bit Windows and in contrast to PartCover you can capture the coverage of 64 Bit assemblies.
PartCover does not support 64 Bit assemblies, and does not work on 64 Bit systems out of the box. You can get it working by using this workaround.
The following table shows which combinations will work:
|NUnit||32/64 Bit||32 Bit|
|MSTest||32 Bit (MSTest does not support 64 Bit)||32 Bit|
Advantages of OpenCover
OpenCover is currently released as a beta version, but it works pretty fine already. In my opinion it has the following advantages:
- Supports 64 Bit assemblies
- No manual DLL registration is required
- Lower memory usage
The provided sample solution contains a simple class and a unit test which can be executed with MSTest and NUnit.
The solution is already compiled in 32 Bit, 64 Bit and AnyCPU mode.
Furthermore the download contains several batch files which enable you to execute the the unit test with OpenCover and PartCover.
Please note: The batch files for MSTest will only work on 64 Bit systems. If you use a 32 Bit OS please adjust the path to MSTest.exe.
OpenCover can be executed in the following way:
OpenCover.Console.exe -register:user -target:nunit-console-x86.exe -targetargs:"/noshadow Test.dll" -filter:+[*]* -output:coverage.xml
PartCover can be executed in the following way:
PartCover.Registration.exe PartCover.dll PartCover.exe --target "nunit-console-x86.exe" --target-args "Test.dll /noshadow" --include [*]* --output coverage.xml PartCover.Registration.exe
After running the unit tests, a XML file containing the coverage information is generated. If you like, you can use ReportGenerator to generate a nice HTML report out of it.
In a previous post I described how you could integrate the code coverage in your build process by using MSBuild.
One final hint: If you want to execute/debug NUnit tests within Visual Studio 2010 you can use this NUnitForVS. This plugin lets you execute the test with the regular test tools: