简体   繁体   English

在Visual Studio 2010中关闭Lamba表达式以获取代码覆盖率

[英]Turning off Lamba Expressions in Visual Studio 2010 for Code Coverage

When looking at code coverage data with Visual Studio 2010 I see the following output under a given namespace: 在使用Visual Studio 2010查看代码覆盖率数据时,我在给定的命名空间下看到以下输出:

SomeClass1
SomeClass2
SomeClass2.< >c__DisplayClass1
SomeClass2.< >c__DisplayClass19
SomeClass2.< >c__DisplayClass28
SomeClass3
SomeClass3.< >c__DisplayClass2F
etc

If I expand out any of the entries with "DisplayClass" in it I see that it is a method that has a lambda expression in it. 如果我展开任何带有“DisplayClass”的条目,我会发现它是一个在其中有lambda表达式的方法。 Due to so many lambda expressions it is difficult to get meaningful data from the code coverage results. 由于如此多的lambda表达式,很难从代码覆盖率结果中获得有意义的数据。

Is there anyway to clean this report up? 无论如何要清理这份报告吗?

The functions generated from a lambda expression are the direct result of the code you wrote. 从lambda表达式生成的函数是您编写的代码的直接结果。 They may come back in the report as having a deceptively high number of lines due to the complier's expansion, but you want to test that their behavior is correct. 由于编译器的扩展,它们可能会在报告中返回,因为它具有看似很高的行数,但您想测试它们的行为是否正确。 Therefore they should be included in the coverage report. 因此,它们应该包含在报道中。

I also agree with the comments: code coverage shouldn't be taken as an exact measurement. 我也同意这些意见:代码覆盖范围不应被视为精确的衡量标准。 I think of it as having one significant digit. 我认为它有一个重要的数字。

Having said all that… I think your best hope is the ExcludeFromCodeCoverage Attribute. 说了这么多......我认为你最好的希望是ExcludeFromCodeCoverage属性。 It's fairly flexible, but is normally applied to a declaration. 它相当灵活,但通常适用于声明。 How you would apply it to a lambda isn't clear to me. 如何将它应用于lambda对我来说并不清楚。

You can mark the class with the DebuggerNonUserCode attribute. 您可以使用DebuggerNonUserCode属性标记该类。

I don't know of any way to exclude particular method patterns, and the compiler is converting your lambda expressions to methods as you've noticed (for example: SomeClass3.< >c__DisplayClass2F) 我不知道有什么方法可以排除特定的方法模式,编译器正在将你的lambda表达式转换为你注意到的方法(例如:SomeClass3。<> c__DisplayClass2F)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM