Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use OpenCover and ReportGenerator to view Unit Test Coverage Results?

I'm a noob to using both OpenCover and ReportGenerator and I'm struggling a bit in understanding how to get them working. I'm using VS.NET 2012 'Professional' which means I don't have access to the built in unit test coverage tooling. I also have ReSharper installed, but don't want to pay for another utility in 'dotCover'

It looks like OpenCover and ReportGenerator will do what I need and I see the documentation that was downloaded alongside, but am missing some understanding. 1st off, when I download the nuget packges for both, what should my target project be? I have a multi layer app, so I'm assuming my unit test project correct, or does it even matter? I see in the documentation, I'm just pointing at the /bin (I think) of a solution using command line commands, so maybe I didn't even need to add these downloads to any particular project (could have been a test harness). Can someone tell me if I have this correct?

Once I have them installed, I'm trying to get unit test coverage metrics, and the docs that came with the package are not as clear as I hoped. Are there any good blog posts or links that walk through using these tool together to get the metrics?

like image 247
atconway Avatar asked May 16 '13 15:05

atconway


People also ask

How do I track unit test coverage?

How to Calculate Test Coverage. Calculating test coverage is actually fairly easy. You can simply take the number of lines that are covered by a test (any kind of test, across your whole testing strategy) and divide by the total number of lines in your application.

How do I open code coverage results?

The code coverage summary can be viewed on the Summary tab on the pipeline run summary. The results can be viewed and downloaded on the Code coverage tab.

How do I show test coverage in Xcode?

Enabling Code Coverage in Xcode Code coverage is enabled in the scheme editor. Click the Covered scheme and choose Edit Scheme.... Select Test on the left and check the checkbox Gather coverage data. That is it.


2 Answers

you do not need to add these to particular project

I use report generator and open cover to generate test coverage results too. This is the script I use to generate the codecoverage using opencover

"C:\Program Files (x86)\OpenCover\OpenCover.Console.exe" -register:user -target:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe" -targetargs:"/noisolation /testcontainer:\"C:\\bin\Debug\.dll\" /resultsfile:C:\Reports\MSTest\.trx" -filter:"+[]" -mergebyhash -output:C:\Reports\MSTest\projectCoverageReport.xml

Note that if your argument needs to escape quotes i.e. to pass arguments with spaces to that target process then you can use ", e.g.: -targetargs:"c:\program files"

This is the script I use to run report generator.

C:\ReportGenerator\bin\ReportGenerator.exe -reports:"C:\Reports\MSTest\projectCoverageReport.xml" -targetdir:"C:\Reports\CodeCoverage"

Hope this helps.

like image 84
SonalKhodiyar Avatar answered Sep 22 '22 17:09

SonalKhodiyar


After several years of using these open source tools, I finally created a comprehensive post on how to use OpenCover and ReportCover to generate unit test coverage metrics.

The post describes how to create the .bat file and the commands needed to do the following:

  • Generate an output report of unit test metrics using OpenCover
  • Generating a .htm report using ReportGenerator
  • Analyzing the output data to interpret unit test coverage metrics

Using OpenCover and ReportGenerator to get Unit Testing Code Coverage Metrics in .NET

like image 42
atconway Avatar answered Sep 20 '22 17:09

atconway