1

I just want to try OpenCover to get Coverage statistics from my app. But I don't understand well how to use it. So here my questions? Does the dll's have to be in the same directory? (my solutions have several projects) Any example to get Coverage using OpenCover? Is necessary to run the site in IIS Express or with ASP.NET development server is ok?

Thanks a lot!

Amit
  • 15,217
  • 8
  • 46
  • 68
mspasiuk
  • 602
  • 1
  • 7
  • 23

2 Answers2

2

I set up open cover as an external tool to make it easier on me.

Download the exe and drop it in a folder with as short a path as possible. then setup and external tool as follows:

Title : Open Cover {this is your choice}
Command: {your path to opencover}\OpenCover.Console.exe
Arguments: -register:user -target:"C:\Progra~1\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" -targetargs:"$(TargetName)$(TargetExt)" -output:coverage.xml  -targetdir:"$(ProjectDir)\bin\debug"
Initial directory: $(TargetDir)

Set it to use output window and close on exit. You will need to adjust the test runner program to suit you, i use vs2012, if you do too, that will make it easier on you.

To use it, click your test project in your solution explorer, then click on the open cover external tool and it will generate you the coverage report. I use it with Report Generator.

Set it up as an external tool too:

 Title: Report Generator
 Command: {Your path to report generator}\ReportGenerator.exe
 Arguments: $(TargetDir)coverage.xml $(TargetDir)\coverageResults

Again, set to close on exit and use output window.

after generating your coverage report, you can then use report generator to create a nice looking html version that you can click through and see the stats.

hth

Slicksim
  • 7,054
  • 28
  • 32
  • Thanks, I'll give a try. I'm using VS2010 and my tests are written with Nunit – mspasiuk Jul 18 '13 at 03:48
  • should still be ok, just adjust the target path to the nuint test runner and set up its arguments and you should be good to go – Slicksim Jul 18 '13 at 08:04
1

The docs that are installed alongside OpenCover carry a lot of useful information about running OpenCover. You should have a copy of this file https://github.com/sawilde/opencover/blob/master/main/OpenCover.Documentation/Usage.pdf in you download package (MSI/ZIP/NUGET)

The DLLs do not need to all be in the same directory but you will normally find that this happens due to the build process. Any assemblies that you want to gather coverage from will require that the PDBs for those assemblies to be in the same directory as the assembly or in the folder referenced by targetdir switch.

Yes you can use it to run iisexpress or the ASP.NET development server use the target switch.

Shaun Wilde
  • 8,228
  • 4
  • 36
  • 56