c# - 从代码覆盖率中排除类 - .runsettings

标签 c# .net code-coverage

我正在使用 .runsettings 文件从代码覆盖率中排除某些代码,但它并没有将它们从代码覆盖率中排除,因为我的代码覆盖率百分比根本没有改变。也没有错误。

代码:

  <CodeCoverage>
    <ModulePaths>
      <Include>
        <ModulePath>.*\.dll$</ModulePath>
      </Include>
      <Exclude>
        <ModulePath>.*\.test.dll</ModulePath>
        <ModulePath>.*\.csv.dll</ModulePath>
      </Exclude>
    </ModulePaths>
    <Functions>
        <Exclude>
            <!-- CORE -->
            <Function>xxx.DI.Mobile.Core.ViewModels.HomeAndContents.xxx</Function>
            <Function>xxx.DI.Mobile.Core.ViewModels.Components.xxxx</Function>
            <Function>xxx.DI.Mobile.Core.ViewModels.Components.xxx</Function>

            <!-- xxx -->
            <Function>^xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.xxx\.xxx$</Function>
            <Function>^xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.xxx\.xxx$</Function>
            <Function>.*\.xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.xxx\.xxx$</Function>
            <Function>.*xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Dashboard\.xxx$</Function>
        </Exclude>
    </Functions>
    <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
    <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
    <CollectFromChildProcesses>True</CollectFromChildProcesses>
    <CollectAspDotNet>False</CollectAspDotNet>
  </CodeCoverage>

长类名只是每个类的完整路径的点符号。它说使用 \. 来分隔 namespace 。

我的一门类(class)的示例是:

namespace xxx.DI.Mobile.Core.State.ViewModels.xxx
{
    public class xxx : yyy
    {

然后将其放入函数标签中,如下所示:

<Function>xxx.DI.Mobile.Core.State.ViewModels.xxx.xxx</Function>

在我的函数标签中尝试这些正则表达式,但还没有起作用:

<Function>^xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Vehicle\.xxx$</Function>
<Function>^xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Vehicle\.xxx$</Function>
<Function>.*\.xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Policies\.xxx$</Function>
<Function>.*xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Dashboard\.xxx$</Function>
<Function>xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Common\.xxx</Function>

为什么它不从代码覆盖率中排除我的任何代码?

最佳答案

<Function>标签排除函数。因此,要排除整个类(class),只需添加 \..*到类(class)结束 - 其中 \.表示点和 .*意味着任何事情。例如类的所有函数。示例:

<Function>xxx.xxx.Mobile.Core.xxx.ViewModels.Vehicle.xxx\..*</Function>

尽管点的意思是 \. ,只有 .无论如何,我的文件夹名称之间的关系都有效。

关于c# - 从代码覆盖率中排除类 - .runsettings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40368548/

相关文章:

c# - 如何在 .NET 中使用 RSA 和 SHA256 对文件进行签名?

c# - 如何更改 ComboBox 的选定项的 ForeColor?

c# - 如何在 sandcaSTLe xml 文档构建中排除不可浏览的成员

c# - 是什么导致 UnhandledExceptionEventArgs.IsTerminating 标志为真或假?

java - 事务处理多层应用程序

angular - Angular 7 中订阅方法中的代码覆盖行

java - Cobertura 无法检测

Xcode 4.5 中的 iOS 代码覆盖率被破坏了吗?

c# - 如何制作整个 C# 应用程序 "unsafe"?

c# - 如何配置 Web Api 2 以在单独的项目中查找 Controller ? (就像我以前在 Web Api 中做的那样)