ExcludeFromCodeCoverage Isn't Working in VS2012

大憨熊 提交于 2019-12-01 14:10:46

问题


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 { ... }

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.

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

Any ideas why this wouldn't work?


回答1:


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

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>

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

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




回答2:


I know the approved answer is good but I wanted to add that if you start your .runsettings file from the one suggested here (https://msdn.microsoft.com/en-us/library/jj159530.aspx) you will have a pretty good base to start with (including the proposed solution here).



来源:https://stackoverflow.com/questions/15362699/excludefromcodecoverage-isnt-working-in-vs2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!