使用属性在Visual Studio中覆盖分析省略code [英] Use attribute to omit code from coverage analysis in Visual Studio

查看:201
本文介绍了使用属性在Visual Studio中覆盖分析省略code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些类,对于怎的,不能或不必进行单元测试。我想从我的覆盖指标排除这些类,这样我可以得到一个更好的感觉在我真正关心的类的报道。现在我必须排除事后的结果。我希望做的是使用属性被排除,这样不包含他们开始与以纪念这些类。 有什么办法来装点一类,它会自动从覆盖率分析中排除属性?无论VS覆盖分析或nCover会工作。

I have some classes that, for one reason or another, cannot be or need not be unit tested. I'd like to exclude these classes from my coverage metrics so that I can get a better feel for the coverage on the classes I actually care about. Right now I have to exclude the results after the fact. What I would like to do is use an attribute to mark those classes as excluded so that they aren't included to begin with. Is there any way to decorate a class with an attribute that will automatically exclude it from coverage analysis? Either VS coverage analysis or nCover will work.

FWIW,这些都是我可以检查该code是正确的保证自己的类。他们大多是围绕现有的框架类包装类,我为了能够嘲笑框架类出已经介绍了。因为包装的get嘲笑了他们没有得到测试。这是OK的,因为他们做的是包装,我所关心的。该框架类的方法

FWIW, these are classes that I can assure myself by inspection that the code is correct. Mostly they are wrapper classes around existing framework classes that I've introduced in order to be able to mock the framework class out. Since the wrapper's get mocked out they don't get tested. That's ok because all they do is wrap the framework class' methods that I care about.

推荐答案

用VS2010开始,我们有<一个href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.$c$canalysis.excludefrom$c$ccoverageattribute.aspx\"><$c$c>ExcludeFrom$c$cCoverageAttribute.评论者已经注意到这NCover工作以及DotCover + NUnit的。用法示例:

Starting with VS2010 we have ExcludeFromCodeCoverageAttribute. Commenters have noted this to work in NCover as well as DotCover + NUnit. Example usage:

[ExcludeFromCodeCoverage]
public class myUntestableClass
{ }

另请参阅该<一个href=\"http://social.msdn.microsoft.com/Forums/en/vstsprofiler/thread/04c7e593-1ae2-46ff-8f55-2ec1200532d7\">link.他们建议使用VSInstr作为命令行工具,它有/排除选项(这是不是很方便)。

Also see this link. They suggest using VSInstr as command line tool, it have /EXCLUDE options (it's not as handy).

这篇关于使用属性在Visual Studio中覆盖分析省略code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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