Issue with Code Coverage in VS 2012

2019-01-28 00:01发布

问题:

I have a simple ASP.Net MVC 4 application with 3 simple tests.

Each of these tests run successfully to completion, however the Code Coverage window gives me the following error:

Empty results generated: No binaries were instrumented. Make sure the tests ran, required binaries were loaded, had matching symbol files, and were not excluded through custom settings. For more information see http://go.microsoft.com/fwlink/?LinkID=253731

I have done some research but nothing has resolved my problem to date.

  • I know the tests run
  • I have .pdb files in the same location as my .dll
  • I am not optimsing by code
  • I cannot find any .testsettings file
  • I Have also run my VS 2012 Ultimate as Administrator, but no luck.

If I find the .coverage file, all it has in it is:

PCHÿ

Not the xmls results or error message I am expecting.

回答1:

I realise this is over a year old. Nevertheless I have just encountered exactly the same issue, even down to the "PCHÿ" text in the .coverage file and have found no solution up 'til now. But surely someone else has had the issue too so, just in case, here's the simple solution:

After checking this MSDN link and following its advice I still had the same issue. So, in the end, I shutdown VS, went to the root solution directory and deleted the .suo file. It has the hidden attribute set so you might need to set explorer to show hidden files.

Restart VS and re-run the code coverage tests. All fine.



回答2:

If you can't make the Code Coverage to work even after you've deleted the *.suo file, please check your Event Viewer for errors. In my case, after each run I had the following error:

"TraceLog Profiler failed in initialization due to a lack of instrumentation methods, process vstest.executionengine.x86.exe"

I've found the answer here.

In case the link is no longer available, I'm pasting the content in here:

If you find yourself with a an empty .coverage file and see errors similar to the below in your event logs you most probably have a corrupt install

(info) .NET Runtime version 4.0.30319.17929 - The profiler has requested that the CLR instance not load the profiler into this process. Profiler CLSID: '{b19f184a-cc62-4137-9a6f-af0f91730165}'. Process ID (decimal): 12624. Message ID: [0x2516].

(Error) TraceLog Profiler failed in initialization due to a lack of instrumentation methods, process vstest.executionengine.x86.exe

Check

a) Environment variable VS110COMNTOOLS is set to \common7\tools

b) Regkey HKLM\SOFTWARE\Microsoft\VisualStudio\11.0\InstallDir is set to your \Common7\IDE\

c) covrun32.dll and covrun64.dll exist in "\Team Tools\Dynamic Code Coverage"

Good luck,

Nadav