Visual Studio 2010 部分类的代码覆盖率

发布于 2024-12-22 20:01:24 字数 613 浏览 1 评论 0原文

我正在使用 Visual Stdio 2010 及其测试和代码覆盖率功能,并且我有一堆生成的代码,我不想将它们包含在代码覆盖率结果中。这些是作为部分类生成的。

我在几个地方读过(例如:如何忽略从代码覆盖率数据生成的代码)如何让代码覆盖率工具忽略整个类或使用属性的特定成员。因此,我修改了生成器,在它生成的所有类上包含 [ExcludeFromCodeCoverage] 属性,但这也阻止了我在部分代码中编写的代码被跟踪代码覆盖率。

如何设置才能使我在部分代码中手动编写的代码包含在代码覆盖率结果中,但生成的代码却不包含在内?我现在看到的唯一选择是深入研究生成器(一个又长又丑的 T4 模板),并在属性/方法级别而不是类级别添加 [ExcludeFromCodeCoverage] 属性。还有别的办法吗?我还没有看到像 [IncludeFromCodeCoverage] 这样的东西,我可以将其添加到我手写的部分属性/方法中,以包含这些属性/方法,同时忽略自动生成的类的其余部分。

I am using Visual Stdio 2010 and its testing and code coverage features, and I have a bunch of generated code that I don't want to be included in code coverage results. These are generated as partial classes.

I've read in a few places (example: How to ignore generated code from code coverage data) how I can have the code coverage tools ignore the entire class or specific members using attributes. So I've modified the generator to include the [ExcludeFromCodeCoverage] attribute on all of the classes it generates, but that prevents the code I write in partials from being tracked for code coverage as well.

How can I set things up such that code I manually write in partials are included in the code coverage results, but the generated code is not? The only option I am seeing now is to dig into the generator (a long, ugly T4 template) and add the [ExcludeFromCodeCoverage] attribute at the property/method level instead of at the class level. Is there another way? I haven't seen anything like [IncludeFromCodeCoverage] that I could add to my handful of properties/methods hand-written in partials to include those while ignoring the rest of the auto-generated class.

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

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

发布评论

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

评论(1

怪我太投入 2024-12-29 20:01:24

您并不是唯一提出此请求的人,因为此条目位于 ExcludeFromCodeCoverage 和其他内容如何忽略生成的代码代码覆盖率数据显示。

另一种方式我已经看到其他一些方法(例如 ncoverpartcover) 覆盖率工具是对结果进行后处理,即如果 XML 使用 xslt 转换 xml 来删除与生成的相关的覆盖率数据部分和然后生成覆盖率报告。

您也许可以应用此方法或类似的方法,因为您似乎可以访问 XML

OpenCover 有一个文件过滤器,允许您排除文件中与过滤器匹配的所有方法,为创建只是在这种情况下,由于生成的文件的名称往往遵循已知的模式,因此它还允许多个过滤器。

You are not alone in requesting this as this entry on ExcludeFromCodeCoverage and other How to ignore generated code from code coverage data shows.

The other way I have seen this done with some other (eg ncover, partcover) coverage tools is to post process the results ie if XML use an xslt transform the xml to remove the coverage data related to the generated partials and then generate the coverage report.

You may be able to apply this approach or something similar as it looks like you can get access to the coverage data in XML.

OpenCover has a file filter that allows you to exclude all methods in a file that matches the filters, created for just this scenario as the names of generated files tend to follow known patterns, it also allows more than one filter.

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