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?
Thanks @atconway for your tutorial. I've updated your .bat script a little, to ease future upgrades, and project changes.
Summarizing, to use OpenCover with NUnit you have to add to your project these nugets:
and here is updated .bat file. To run it just edit "settings" and save script as .bat file in root of your project.
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:.htm
report using ReportGeneratorUsing OpenCover and ReportGenerator to get Unit Testing Code Coverage Metrics in .NET
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
Note that if your argument needs to escape quotes i.e. to pass arguments with spaces to that target process then you can use \" i.e. -targetargs:"\"c:\program files\"
This is the script I use to run report generator.
Hope this helps.
It is a hell to configure opencover for multiple test containers.
Use this my smart Powershell script, it can give you some ideas.
https://github.com/rpokrovskij/opencover4vs.ps1/blob/master/opencover4vs.ps1
you need to configure two major things : how to find your test dlls and which namespaces to include to the output. I do it this way:
Note, my tests starts from prefix Vse. You need the
Debug\Prefix
key to filter out core nUnit tests from folders likeDebug\netcore1.1\Vse
.