VS2013 中的代码覆盖率显示测试覆盖率而不是实际代码

Code coverage in VS2013 show coverage of Test and not actual code

我正在关注 VS 2013 http://msdn.microsoft.com/en-us/library/dd537628.aspx 中代码覆盖率的文章。它显示了测试的覆盖范围,而不是实际代码。

我已从 Test Explorer 中选择单元测试并单击 Analyze Code Coverage -> Selected Test。代码覆盖率 window 在底部打开,显示单元测试的 dll 及其覆盖率,未显示具有代码覆盖率的实际 dll。

另外,我查看了文章 http://msdn.microsoft.com/library/jj159523.aspx。将 pdbs 和 dll 复制到同一位置。在代码覆盖率 window 中,消息是

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"

对此有什么想法吗?

我已经尝试了 link 中给出的步骤。

http://blogs.msdn.com/b/allendm/archive/2012/09/08/empty-coverage-file-with-profiler-related-errors-in-the-event-logs.aspx

如果您使用的是 VS 2013,则稍作更改。

a) 环境变量 VS120COMNTOOLS 设置为 \common7\tools

b) 注册码 HKLM\SOFTWARE\Microsoft\VisualStudio.0\InstallDir 设置为您的 \Common7\IDE\

c) covrun32.dll 和 covrun64.dll 存在于“\Team Tools\Dynamic Code Coverage”

删除了 VS110COMNTOOLS 环境变量。这些更改对我有用。

我能够解决我的问题。我的生产 DLL 上没有发生代码覆盖的原因是:原因 = "has_fixed_base"。将此设置更改为:是 (/DYNAMICBASE) 后,覆盖范围开始工作。

检查这些步骤会有所帮助:

  1. 打开项目属性
  2. 转到Linker->Advanced
  3. 在那,勾选Randomized Base Address
  4. 将其更改为是 (/DYNAMICBASE)

这应该开始代码覆盖。