Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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. Due to so many lambda expressions it is difficult to get meaningful data from the code coverage results.

Is there anyway to clean this report up?

like image 333
Idaho Avatar asked Nov 13 '22 15:11

Idaho


1 Answers

The functions generated from a lambda expression are the direct result of the code you wrote. 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. It's fairly flexible, but is normally applied to a declaration. How you would apply it to a lambda isn't clear to me.

like image 60
ErnieL Avatar answered Dec 05 '22 13:12

ErnieL