10

trying to run the open cover as below

opencover.console.exe -target:"C:\Users\rkapiset\Downloads\xunit-1.8\xunit.console.clr4.x86.exe" -targetargs:"""E:\Office\CRM\dotnet\1 - UI\EYC.CRM.UI.Tests\bin\Debug\EYC.CRM.UI.Tests.dll""" -filter:+[EYC]* -output:coverage.xml

below is the result

61 total, 3 failed, 0 skipped, took 1.674 seconds
Visited Classes 0 of 0 (NaN)
Visited Methods 0 of 0 (NaN)
Visited Points 0 of 0 (NaN)
Unvisited Classes
Unvisited Methods

Any hints where i'm going wrong? thanks in advance.

Adam Ralph
  • 29,453
  • 4
  • 60
  • 67
Ravindra
  • 101
  • 1
  • 1
  • 3
  • The filter may also need to be -filter:"+[EYC]* -[EYC.CRM.UI.Tests]*" else you may get coverage of your test classes as well which may not be preferable – Shaun Wilde Jul 24 '11 at 09:34

3 Answers3

8

There are a couple of keys to getting this to work.

  1. find open cover
  2. tell it to use xunit.console.exe
  3. give it arguments for xunit.console.exe using targetargs
  4. give xunit the debug versions of both the test dll and application dll
  5. instruct xunit to NOT use a shadowcopy (so all PDB debug files are available in its working directory)
  6. comment quotes in paths in targetargs with a backslash
  7. filter out classes in the ".Tests" project from coverage
  8. use -register to do something magical
  9. run as administrator (not an issue if UAC is turned off on your machine)

Example:

"C:\OpenCover.4.6.166\tools\OpenCover.Console.exe" -output:"C:\MyProject\coverage.xml" "-target:C:\MyProject\packages\xunit.runner.console.2.0.0\tools\xunit.console.exe" -targetargs:"\"C:\MyProject\Project.Tests\bin\Debug\Project.Tests.dll\" \"C:\MyProject\Project\bin\Debug\Project.exe\" -noshadow" -filter:"+[*]Project.* -[*.Tests]*" -register

Cite: http://derekwilson.net/derekblog/post/2012/05/29/Using-OpenCover-and-xUnit.aspx

cocogorilla
  • 1,815
  • 14
  • 36
4

Have you registered the profiler?

try the -register switch or if under UAC -register:user

All the switches are explained on the OpenCover Wiki

Alternative you can use regsvr32 on each of the profilers OpenCover.Profiler.dll in the x86 and x64 folders in the installed program files folder

Shaun Wilde
  • 8,228
  • 4
  • 36
  • 56
  • thanks for the prompt response. made all the changes as you said. but no luck yet..opencover.console.exe -register:"user" -target:"C:\Users\rkapiset\Downloads\xunit-1.8\xunit.console.clr4.x86.exe" -targetargs:"""E:\Office\CRM\dotnet\1 - UI\EYC.CRM.UI.Tests\bin\Debug\EYC.CRM.UI.Tests.dll""" -filter:+[EYC*]* -output:coverage.xml – Ravindra Jul 24 '11 at 10:05
  • 1
    Have registered OpenCover.Profiler.dll under x86 installed folder. still the same result set. any more points that i need to take care of? – Ravindra Jul 24 '11 at 10:07
  • 3
    Try the /noshadow switch on your xunit commandline - in order to correctly instrument the code the coverage tool needs to find the pdb file - xunit looks like it copies the file to another location and as such no PDB file found and hence no coverage. – Shaun Wilde Jul 24 '11 at 12:16
  • @Shaun Wilde, I've run regsvr32 against both the profiler DLLs and I'm still getting no output from `-output`. Any change you can expland on what's going on here. Cheers – Greg B Aug 18 '11 at 22:49
  • It's hard to use the comment section on SO to discuss another issue (i.e. to request command lines etc), perhaps you should raise a new Q on SO or raise an issue on the opencover project on github. – Shaun Wilde Aug 19 '11 at 04:13
  • @ShaunWilde the behavior reported by OP shows that tests are running but no coverage results are coming out of the profiler... applying the noshadow switch to the targetargs fixes the issue for me. – cocogorilla Sep 25 '15 at 00:25
  • @cocogorilla that is also a possible resolution - this Q is now 4 years old – Shaun Wilde Sep 25 '15 at 06:51
0

Try to add -register:user in your code. If this fails, then you must be missing Microsoft Visual C++ 2010 Redistributable Package (x86).. This is explained here

RockWorld
  • 1,278
  • 2
  • 11
  • 24
  • I believe Ravindra (+supporting comment from myself) covered the registration issue. FYI: OpenCover is no longer statically linked to the libraries concerned this can be determined by following the article and the supporting issue on GitHub. – Shaun Wilde Sep 23 '12 at 21:33
  • I needed to install it when tried to use opencover with visual studio 2008 applications. Thanks Shaun for tool! – RockWorld Sep 24 '12 at 01:58
  • How long ago was that as the most recent versions of OpenCover should no longer require the 'redistributables' installed? – Shaun Wilde Sep 24 '12 at 02:58
  • Just 2 days back, I tried on Windows Vista with visual studio 2008. Do you generate any log file during installation? I can then check and let you know. – RockWorld Sep 24 '12 at 03:26
  • @RockWorld the link is dead on "this is explained here" – jcolebrand Jul 24 '18 at 03:03