Entries:
Comments:
Discussions:

Loading user information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading user information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Free Unit Testing Code Coverage with OpenCover and ReportGenerator

So you want to do development "right," you write unit tests and now want to see your code coverage? But you're not using a Visual Studio Enterprise?

Phil Fresle comes to the rescue, showing off how you can use a number of free projects to get your code coverage reports today...

OpenCover and ReportGenerator Unit Test Coverage in Visual Studio 2013 and 2015

The usual choices for getting code coverage metrics in Visual Studio is to buy the Enterprise version of Visual Studio or buy the dotCover third party tool, both of which are costly, especially if you are developing small applications yourself and want to check the coverage of your unit tests.

There is a free NuGet package for generating code coverage metrics called OpenCover, and together with another free NuGet package, ReportGenerator, can give you code coverage reports for free.

The problem I found, however, was the documentation available to get the tool working was less than adequate for my purposes and it took several hours of faff to get it working for me. To save you time and money I have documented my experience here.

The following were all referenced in the creation of this document:

https://www.nuget.org/packages/OpenCover/
https://www.nuget.org/packages/ReportGenerator/
https://www.nuget.org/packages/NUnit.ConsoleRunner/
http://www.allenconway.net/2015/06/using-opencover-and-reportgenerator-to.html
http://www.nootn.com.au/2014/01/code-coverage-with-opencover-example.html#.VxiNn_krLDc

I have tested that this works in Visual Studio 2013 Professional and Visual Studio 2015 Community Edition, with both MSTest and NUnit.

I assume you already have a solution with application project that you are testing with a test project, and where you are using NUnit for that testing that you have already included the NUnit NuGet package.

... [Click through to read the rest of the post]

OpenCover/opencover

OpenCover is a code coverage tool for .NET 2 and above (Windows OSs only - no MONO), with support for 32 and 64 processes and covers both branch and sequence points. OpenCover was started after attempts to make PartCover support 64-bit processes got just a little too complicated.

The latest releases can be downloaded from releases or from the OpenCover mirror site on bitbucket. Alternatively why not try the nuget package (this is the most popular).

...

Reports

OpenCover produces an XML output file that can be used to generate a graphical report. Thankfully you do not have to do that yourself as Daniel Palme has kindly added support for OpenCover to his Report Generator tool.

This the output from Report Generator for OpenCover.Framework.dll looks something like this.

image

...

danielpalme/ReportGenerator

ReportGenerator converts XML reports generated by OpenCover, PartCover, Visual Studio or NCover into human readable reports in various formats. http://danielpalme.github.io/ReportGenerator

...

ReportGenerator converts XML reports generated by OpenCover, PartCover, Visual Studio or NCover into human readable reports in various formats.

The reports do not only show the coverage quota, but also include the source code and visualize which lines have been covered.

ReportGenerator supports merging several reports into one. It is also possible to pass one XML file containing several reports to ReportGenerator (e.g. a build log file).

The following output formats are supported by ReportGenerator:

  • HTML, HTMLSummary, HTMLChart
  • XML, XMLSummary
  • Latex, LatexSummary
  • TextSummary
  • CsvSummary
  • PngChart
  • Badges
  • Custom reports

Compatibility:

Also available as NuGet package: http://www.nuget.org/packages/ReportGenerator

...

image

...



Tags:

Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation
    Unsubscribing
    Subscribing

Remove this comment

Remove this thread

Close

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.