ExcludeFromCodeCoverage在VS2012中不起作用 [英] ExcludeFromCodeCoverage Isn't Working in VS2012

查看:74
本文介绍了ExcludeFromCodeCoverage在VS2012中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有一个我不想在代码覆盖率数字中显示的类.我在类定义中添加了[ExcludeFromCodeCoverage]属性,如下所示:

I have a class in my code that I don't want showing up in code coverage numbers. I added the [ExcludeFromCodeCoverage] attribute to the class definition like this:

[ExcludeFromCodeCoverage]
public class MyClass { ... }

根据文档( http://msdn .microsoft.com/en-us/library/system.diagnostics.codeanalysis.excludefromcodecoverageattribute.aspx ),这应该是我所需要的,但是该类仍会显示在代码覆盖率分析中.

According to the docs (http://msdn.microsoft.com/en-us/library/system.diagnostics.codeanalysis.excludefromcodecoverageattribute.aspx) this should be all I need, but the class still shows up in code coverage analysis.

如果要这样做,我正在使用VS2012/.NET 4.5.

I'm using VS2012/.NET 4.5 if that matters.

有什么想法为什么行不通?

Any ideas why this wouldn't work?

推荐答案

这是正在发生的事情,这是我修复它的方法.

Here's what was going on, and here's how I fixed it.

我正在使用.runsettings文件将某些程序集排除在代码范围之外.好像每当您包含一个.runsettings文件时,您必须包括以下配置:

I was using a .runsettings file to exclude certain assemblies from being included in code coverage. Seems like whenever you include a .runsettings file, you must include the following configuration:

<Attributes>
    <Exclude>
        <Attribute>^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
    </Exclude>
</Attributes>

.runsettings文件中的内容似乎并不重要-必须存在该文件才能使[ExcludeFromCodeCoverage]工作.

It doesn't seem to matter what you have in the .runsettings file - this has to be there for [ExcludeFromCodeCoverage] to work.

仅供参考,请参阅本文以获取有关.runsettings文件的更多信息: http://msdn.microsoft.com/en-us/library/jj159530.aspx

FYI see this article for more information on the .runsettings file: http://msdn.microsoft.com/en-us/library/jj159530.aspx

这篇关于ExcludeFromCodeCoverage在VS2012中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆