使用 Opencover + xunit 没有结果

11

我想使用今天下载的OpenCover来获取我的测试覆盖率。这是我使用的命令行:

OpenCover.Console.exe -target:"c:\Programmes2\xunit\xunit.console.clr4.x86.exe" -targetargs:"""C:\Sources\Project\BackOffice.Tests\bin\Debug\BackOffice.Tests.dll"" /noshadow " -output:bo.coverage.xml -targetdir:"C:\Sources\Project\BackOffice.Tests\bin\Debug" -filter:+[*]*

这里是我得到的输出

xUnit.net console test runner (32-bit .NET 4.0.30319.269)
Copyright (C) 2007-11 Microsoft Corporation.

xunit.dll:     Version 1.9.0.1566
Test assembly: C:\Sources\Project\BackOffice.Tests\bin\Debug\BackOffice.Tests.dll

31 total, 0 failed, 0 skipped, took 2.760 seconds
Committing...
No results - no assemblies that matched the supplied filter were instrumented
    this could be due to missing PDBs for the assemblies that match the filter
    please review the output file and refer to the Usage guide (Usage.rtf)
生成的报告始终相同。
<?xml version="1.0" encoding="utf-8"?>
<CoverageSession xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Modules />
</CoverageSession>
稍微补充一下背景信息:PDB文件存在于目标文件夹中,我正在以管理员身份运行命令提示符。测试的项目是一个.NET 4/MVC 3应用程序。我的计算机运行Windows 7/32位。关于这个问题,不确定是否有任何相关性,但是即使我将目标平台强制为x86,x86文件夹也是空的。
此外,当我尝试使用regsvr32注册OpenCover.Profiler.dll时,我收到一个错误消息,说该dll可能与我的Windows版本不兼容。
如果我尝试使用-register或-register:user参数,则会出现异常:
An exception occured: Failed to register(user:True,register:True,is64:False):3 the profiler assembly; you may want to look into permissions or using the -register:user option instead. C:\Windows\system32\regsvr32.exe /s  /n /i:user "C:\Sources\Opencover\sawilde-opencover-be6e491\main\bin\Debug\x86\OpenCover.Profiler.dll"
stack:    
    à OpenCover.Framework.ProfilerRegistration.ExecuteRegsvr32(Boolean userRegistration, Boolean register, Boolean is64) dans C:\Sources\Opencover\sawilde-opencover-be6e491\main\OpenCover.Framework\ProfilerRegistration.cs:ligne 59
    à OpenCover.Framework.ProfilerRegistration.ExecuteRegsvr32(Boolean userRegistration, Boolean register) dans C:\Sources\Opencover\sawilde-opencover-be6e491\main\OpenCover.Framework\ProfilerRegistration.cs:ligne 45
    à OpenCover.Framework.ProfilerRegistration.Register(Boolean userRegistration) dans C:\Sources\Opencover\sawilde-opencover-be6e491\main\OpenCover.Framework\ProfilerRegistration.cs:ligne 31
    à OpenCover.Console.Program.Main(String[] args) dans C:\Sources\Opencover\sawilde-opencover-be6e491\main\OpenCover.Console\Program.cs:ligne 82

我还尝试了一个DLL项目(.net4),用不同的项目(也是xunit)进行测试,但结果相同(缺乏)。

任何帮助都将不胜感激!


看起来你已经构建了代码的堆栈跟踪 - 你尝试过官方发布版吗? - Shaun Wilde
好的,我现在感觉很愚蠢,因为你一提到它,我就找到了下载链接。第一次没有找到下载链接,我感到很惊讶,但是由于页面的主要自述文件链接只提到了构建,所以我没有再看更多。谢谢你的指引,我下周二会尝试这种方式,并相应更新这个问题。 - Sebastien F.
1个回答

7

下载发布包解决了注册参数异常的问题。但是运行相同的命令行会生成多个此类错误:

BackOffice.Tests.HomeControllerShould.Redirect_To_Action_Feed_Index [FAIL]
   System.MissingMethodException : Méthode introuvable : 'Void     System.CannotUnloadAppDomainException.SafeVisited(Int32)'.
   Stack Trace:
      à BackOffice.Tests.HomeControllerShould..ctor()

具有此结果:

31 total, 31 failed, 0 skipped, took 0.241 seconds
Committing...
Visited Classes 0 of 44 (0)
Visited Methods 0 of 183 (0)
Visited Points 0 of 1352 (0)
Visited Branches 0 of 322 (0)

==== Alternative Results (includes all methods including those without corresponding source) ====
Alternative Visited Classes 0 of 53 (0)
Alternative Visited Methods 0 of 268 (0)

在寻找类似问题时,我发现了github上的这个问题并尝试使用-oldStyle参数解决了我的问题。

@Shaun Wilde,如果您再次看到这个问题,能否告诉我们这是否是推荐的解决方法以及使用它是否会损失一些东西(我还建议将此参数添加到文档页面中)。


1
这是我目前所知道的唯一解决方法...唯一的问题可能是信任问题,例如如果您正在使用AllowPartiallyTrustedCallersAttribute或其他类似的属性。旧式技术是我最初用来检测代码的方式,直到我遇到了APTCA和Silverlight的问题。 - Shaun Wilde
1
Github问题链接已更改为:https://github.com/opencover/opencover/issues/88 - Junle Li
9年后仍然有意义! - AXMIM

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接