使用 .runsettings 从代码覆盖率中排除程序集

2023-12-21

当为包含多个项目的解决方案运行代码覆盖率时,我注意到代码覆盖率还包括我的测试程序集。

我发现一篇文章建议使用以下 .runsettings 模板:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <Configuration>
          <CodeCoverage>
            <ModulePaths>
              <Include>
                <!-- Do not specify any includes. This will attempt to include all binaries -->
              </Include>
              <Exclude>
                <!-- Exclude modules that aren't to be processed, by their name / path -->
                <ModulePath>.*Tests\.dll$</ModulePath> <!-- I put it here -->
              </Exclude>
            </ModulePaths>

            <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
            <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
            <CollectFromChildProcesses>True</CollectFromChildProcesses>
            <CollectAspDotNet>False</CollectAspDotNet>
            <!--
Additional paths to search for symbol files. Symbols must be found for modules to be instrumented.
If symbols are alongside the binaries, they are automatically picked up. Otherwise specify the here.
Note that searching for symbols increases code coverage runtime. So keep this small and local.

<SymbolSearchPaths>             
  <Path>C:\Users\User\Documents\Visual Studio 11\Projects\ProjectX\bin\Debug</Path>
  <Path>\\mybuildshare\builds\ProjectX</Path>
</SymbolSearchPaths>
-->
            <Functions>
              <Exclude>
                <Function>^std::.*</Function>
                <Function>^ATL::.*</Function>
                <Function>.*::__GetTestMethodInfo.*</Function>
                <Function>^Microsoft::VisualStudio::CppCodeCoverageFramework::.*</Function>
                <Function>^Microsoft::VisualStudio::CppUnitTestFramework::.*</Function>
                <Function>.*::YOU_CAN_ONLY_DESIGNATE_ONE_.*</Function>
              </Exclude>
            </Functions>
            <Attributes>
              <Exclude>
                <Attribute>^System.Diagnostics.DebuggerHiddenAttribute$</Attribute>
                <Attribute>^System.Diagnostics.DebuggerNonUserCodeAttribute$</Attribute>
                <Attribute>^System.Runtime.CompilerServices.CompilerGeneratedAttribute$</Attribute>
                <Attribute>^System.CodeDom.Compiler.GeneratedCodeAttribute$</Attribute>
                <Attribute>^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
              </Exclude>
            </Attributes>
            <Sources>
              <Exclude>
                <Source>.*\\atlmfc\\.*</Source>
                <Source>.*\\vctools\\.*</Source>
                <Source>.*\\public\\sdk\\.*</Source>
                <Source>.*\\microsoft sdks\\.*</Source>
                <Source>.*\\vc\\include\\.*</Source>
              </Exclude>
            </Sources>
            <CompanyNames>
              <Exclude>
                <CompanyName>.*microsoft.*</CompanyName>
              </Exclude>
            </CompanyNames>
            <PublicKeyTokens>
              <Exclude>
                <PublicKeyToken>^B77A5C561934E089$</PublicKeyToken>
                <PublicKeyToken>^B03F5F7F11D50A3A$</PublicKeyToken>
                <PublicKeyToken>^31BF3856AD364E35$</PublicKeyToken>
                <PublicKeyToken>^89845DCD8080CC91$</PublicKeyToken>
                <PublicKeyToken>^71E9BCE111E9429C$</PublicKeyToken>
                <PublicKeyToken>^8F50407C4E9E73B6$</PublicKeyToken>
                <PublicKeyToken>^E361AF139669C375$</PublicKeyToken>
              </Exclude>
            </PublicKeyTokens>
          </CodeCoverage>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

现在的问题是,一旦我在 TEST\Test 设置菜单中检查 .runsettings 文件,我就会看到代码覆盖率仅分析解决方案中的许多程序集之一。

即使我把线去掉

 <ModulePath>.*Tests\.dll$</ModulePath> <!-- I put it here -->

仅分析一个装配体。我想避免将所有程序集添加到“包含”列表中,我只需要排除所有测试程序集。

为什么 .runsettings 使代码覆盖率只能看到我的 VS 解决方案中的程序集之一?


问题是时期 https://stackoverflow.com/a/16616574/1045767。由于某种原因,正则表达式对此感到窒息。您可以通过转义句点来绕过它,如下所示:

<ModulePaths>
    <Include>
        <ModulePath>.*MyCompany\.Namespace\.Project\.dll$</ModulePath>
    </Include>
    <Exclude>
        <ModulePath>.*ThirdParty\.Namespace\.Project\.dll$</ModulePath>
    </Exclude>
</ModulePaths>

此外,空包含是有效的,意味着包含所有模块。微软提供的样本的评论指出:

<!--
About include/exclude lists:
Empty "Include" clauses imply all; empty "Exclude" clauses imply none.
Each element in the list is a regular expression (ECMAScript syntax).
See http://msdn.microsoft.com/library/2k3te2cs.aspx.
An item must first match at least one entry in the include list to be included.
Included items must then not match any entries in the exclude list to remain included.
-->
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 .runsettings 从代码覆盖率中排除程序集 的相关文章

随机推荐

  • IOError:[Errno 2]没有这样的文件或目录(当它确实存在时)Python [重复]

    这个问题在这里已经有答案了 我正在通过 python 中的 uart 传输文件文件夹 下面您可以看到简单的功能 但有一个问题 因为我收到如标题所示的错误 IOError Errno 2 No such file or directory 1
  • 在 EXCEL 中构建 SQL SELECT 语句

    我正在尝试在 Excel 中构建 SQL 语句 Sample 我正在尝试构建 sql 语句 但只想在 DIM 列中有值时添加列 因此 在 SQL 中执行时 SQL 看起来很整洁 没有任何语法错误 这里如何消除 from 关键字之前的多余逗号
  • 酿造更新破坏了什么?

    自制程序工作正常 直到我做了一个brew update 好几个月没有更新了 brew 更新完成后 每个brew命令会产生相同 相似的错误消息 usr local Library Homebrew global rb 6 in require
  • 两个菜单 Android 应用程序

    我工作的公司有一个 iOS 应用程序 它有两个滑动菜单 左侧一个用于导航 右侧一个显示应用程序范围的上下文信息和操作 iOS 应用程序有一个类似于 ActionBar 的小部件 在显示任一菜单时 意味着它是隐藏的 它会随主内容窗格一起滑动
  • TypeError:错误的参数类型类(预期模块)与控制器有关

    所以我有一个名为 guest controller rb 的控制器 如下所示 class GuestsController lt ApplicationController include Data def index display da
  • NSubstitute - 检查传递给方法的参数

    我们目前正在从 RhinoMocks 迁移到 NSubstitute 我有一个接受类型对象的方法DatabaseParams 该类具有以下结构 简化 public class DatabaseParams public string Sto
  • HTTP协议的PUT和DELETE及其在PHP中的使用

    介绍 我已阅读以下内容 超文本传输 协议 HTTP 是网络的生命 每次传输文档或发出 AJAX 请求时都会用到它 但令人惊讶的是 HTTP 在一些 Web 开发人员中相对陌生 HTTP 动词构成了 统一接口 约束的主要部分 并为我们提供了与
  • 当数据库中添加新行时,必须调用外部命令行程序

    当向数据库中的一个表添加新行时 MySQL 数据库是否可以调用外部 exe 文件 我需要监视数据库中的更改 因此当进行相关更改时 我需要在数据库之外执行一些批处理作业 查德 伯奇 Chad Birch 有一个好主意 使用MySQL 触发器和
  • 将 Rewire 与 TypeScript 结合使用

    我正在使用 TypeScript 开发一个 React Native 项目 为了编写我的单元测试 我想使用babel 插件 重新布线 https github com speedskater babel plugin rewire模拟我的模
  • Python Pillow:在发送到第三方服务器之前使图像渐进式

    我有一个使用 Django Forms 上传的图像 它在变量中可用InMemoryFile我想做的就是让它进步 使图像成为渐进式的代码 img Image open source img save destination JPEG qual
  • EntityManager 中的 SessionFactory 抛出异常

    我尝试使用以下几行从 JPA 的 EntityManager 获取 Hibernate 的 SessionFactory PersistenceContext EntityManager manager public SessionFact
  • 以深度优先顺序生成数组笛卡尔积的算法

    我正在寻找一个示例 说明如何在 Ruby 类似 C 的语言或伪代码 中创建可变数量的整数数组 每个数组的长度不同 的笛卡尔积 并以特定顺序逐步遍历结果 因此 1 2 3 1 2 3 1 2 3 1 1 1 2 1 1 1 2 1 1 1 2
  • Sencha Touch MVC 最佳实践

    我试图将我的注意力集中在 Sencha Touch 的 MVC 框架上 但我发现了几种不同的方法 其中一处 发现here http vimeo com 17705448 SenchaCon 2010 上提出了一种构建 Sencha Touc
  • 关闭:使用未解析的标识符“self”

    我正在解析 Swift 语言指南教程 来自 Apple iOS 开发库 并为每一章创建一个单独的 swift 文件 在每个文件中 我创建多个函数 在其中隔离它们提供的代码片段 一切正常 直到测试闭包的强引用循环 由于某种原因 如果在函数内部
  • RampUsersPerSec 函数的真正作用是什么?

    我发现加特林文档对特定功能有点不清楚 rampUsersPerSec 在给定持续时间内每秒注入随机数量的用户 rate1 至 rate2 期间 dur 单位 从起始速率1注入用户 目标速率2 在给定持续时间内以每秒用户数定义 例如 在 10
  • TestFlight 处理状态

    上传新版本的应用程序后试飞 应用程序有状态加工几分钟后 程序集从列表中消失 之前没有这个问题 请问是什么原因呢 检查邮箱 您将收到来自 Apple 的邮件 如果您仍然没有收到任何邮件 请检查 plist 和权限 确保您已在 plist 中包
  • 如何在JPQL中应用正则表达式?

    我使用 JPA Hibernate 作为持久层 我需要添加一个基于正则表达式的 WHERE 子句 这样的一些模式是 SELECT FROM TableName where REGEXP LIKE ColumnName Pattern 我从结
  • SQL Server Express连接字符串

    sql server连接字符串和express版本有区别吗 By default though I don t recommend it1 Sql Express is installed as a named instance http
  • 内置可调用作为 Django Field 的默认参数

    我有一个 JSONField 需要对其应用默认字典 根据文档 我避免将可变字典传递到默认字段 这是通过将复制方法传递给默认参数来完成的 如下所示 default dict some key some value class MyModel
  • 使用 .runsettings 从代码覆盖率中排除程序集

    当为包含多个项目的解决方案运行代码覆盖率时 我注意到代码覆盖率还包括我的测试程序集 我发现一篇文章建议使用以下 runsettings 模板