dotnet thoughts 

a dotnet developer's technical blog

Getting Code coverage using Open Cover and NUnit

In the last post I blogged about how to get code coverage using MSTest and Part cover. In this post I am blogging about measuring code coverage with Open cover. Today I found another alternative to measure code coverage. Its called Open cover. You can download Open Cover from here. Compared to Part cover, Open cover doesn’t have a UI part. Also open cover gives better performance compared to Part cover. You can find Performance comparison here. You can find the OpenCover command line parameters in Github wiki.

In this example I am using a NUnit as the unit testing application. And the following command gets the code coverage in XML file.

"C:\Program Files (x86)\OpenCover\OpenCover.Console.exe"
-filter:"-[DataAccess.*]* +[DataAccess*]* -[DataAccess.Test]"
-target:"C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console-x86.exe"
-register:user -targetargs:"/nologo DataAccess.Test.dll"
-output:coverage.xml

The filter part is similar like, PartCover application, like I am profiling only DataAccess component and I am not profiling DataAccess.Test application. And no need to specify

the filters to remove System and NUnit type of assemblies.

Open cover generate results as XML files and with the help of Report Generator application you can view the coverage details.

And here is the syntax to get the details using Report Generator.

ReportGenerator.exe" coverage.xml "C:\Study\CodeCoverage\"

And here is the report generated using ReportGenerator summary and next is the detailed report.

Code coverage summary

Code coverage summary

And next is the detailed report.

Detailed Coverage details

Detailed Coverage details

Happy Code coverage :)