如何在 TeamCity 中排除 dotCover 覆盖的类型和方法?

发布于 2024-11-01 04:52:54 字数 424 浏览 4 评论 0原文

我有一个现有的 C# 4 项目,我已使用 TestDriven.Net 和 Visual Studio 覆盖率功能检查了该项目的测试覆盖率,即 Test With ->上下文菜单的覆盖范围。

该项目包含一些我不想覆盖的代码,我已经通过为这些类型和方法添加 [ExcludeFromCodeCoverage] 解决了这个问题。

我们刚刚将 TeamCity 升级到 6.0.3,并且我在 NUnit 构建步骤中添加了 dotCover 覆盖范围。

我已经设法在“过滤器”部分中删除对外部程序集(例如 NHibernate)的覆盖(通过明确说明我想要覆盖的程序集),但我正在努力解决如何从所覆盖的程序集中排除类型和方法。

在此处输入图像描述

I've got an existing C# 4 project which I've checked the test coverage for by using TestDriven.Net and the Visual Studio coverage feature, i.e. Test With -> Coverage from the context menu.

The project contains some code I don't want covered, and I've solved that by adding the [ExcludeFromCodeCoverage] for those types and methods.

We've just upgraded TeamCity to 6.0.3, and I've added dotCover coverage to the NUnit build step.

I've managed to remove coverage for external assemblies such as NHibernate in the "Filters" section (by explicitly state the assemblies for which I want coverage), but I'm struggling with how to exclude types and methods from covered assemblies.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黑色毁心梦 2024-11-08 04:52:54

好吧,马丁,我明白了!仅花了一个小时随机查看过滤器语法...当文档说要添加这样的过滤器时,

+:myassembly=*;type=*;method=***

他们的真正意思是...其中 <> 中的任何内容都完全替换为你和其他任何东西都是文字

+:<myassembly>;type=<filter>;method=<filter>

所以,我想要的过滤器是包含一个程序集(来自一堆程序集),然后排除该程序集中的一些命名空间。我写

+:Omnyx.Scanner
-:Omnyx.Scanner;type=Omnyx.Scanner.Simulation.*
-:Omnyx.Scanner;type=Omnyx.Scanner.ToolsCommon.*

Ok, Martin, I figured it out! It only took an hour of randomly poking at the filter syntax... when the documentation says to add a filter like this

+:myassembly=*;type=*;method=***

They really mean this... where anything in <> is replaced entirely by you and anything else is a literal

+:<myassembly>;type=<filter>;method=<filter>

So, the filter I wanted was to include a single assembly (from a bunch of assemblies) and then exclude a few namespaces in that assembly. I wrote

+:Omnyx.Scanner
-:Omnyx.Scanner;type=Omnyx.Scanner.Simulation.*
-:Omnyx.Scanner;type=Omnyx.Scanner.ToolsCommon.*
半衬遮猫 2024-11-08 04:52:54

查看命令行的覆盖率分析 - 应用过滤器页。看起来您可以在“过滤器”部分中设置排除项,类似于排除整个程序集的方式。

假设您想要忽略 MyStuff 类中包含的名为 DoStuff 的方法,该类位于 MyAwesomeAssembly 库中。那么您的 dotCover XML 应该如下所示:

<Filters>
  <ExcludeFilters>
     <FilterEntry>
       <ModuleMask>MyAwesomeAssembly</ModuleMask>
       <ClassMask>MyStuff</ClassMask>
       <FunctionMask>DoStuff</FunctionMask>
     </FilterEntry>
  </ExcludeFilters>
</Filters>

免责声明: 我不使用 dotCover,所以我不能 100% 确定这是否真的有效。

Take a look at the Coverage Analysis from the Command Line - Applying filters page. It looks like you can set up exclusions in the Filters section, similar to how you excluded entire assemblies.

Let's say you want to ignore a method called DoStuff contained in a class MyStuff, which is in the MyAwesomeAssembly library. Then your dotCover XML should look something like this:

<Filters>
  <ExcludeFilters>
     <FilterEntry>
       <ModuleMask>MyAwesomeAssembly</ModuleMask>
       <ClassMask>MyStuff</ClassMask>
       <FunctionMask>DoStuff</FunctionMask>
     </FilterEntry>
  </ExcludeFilters>
</Filters>

Disclaimer: I don't use dotCover, so I'm not 100% sure if this will actually work.

风为裳 2024-11-08 04:52:54

TeamCity 文档关于过滤器选项的说明如下:

使用以下语法指定要分析每行一个的程序集:+:myassemble=;type=;method=*

使用
-:我的程序集
从代码覆盖率中排除程序集。此处支持星号通配符 (*)。

This is what the TeamCity docs says about the filter options:

Specify assemblies to profile one per line using following syntax: +:myassembly=;type=;method=*

Use
-:myassembly
to exclude an assembly from code coverage. Asterisk wildcard (*) is supported here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文