coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.94k stars 386 forks source link

ExcludeFromCodeCoverage attribute ignored for anonymous calls #1336

Closed nics71 closed 2 years ago

nics71 commented 2 years ago

The following block of code is showing as not included by Unit Tests even the method has the ExcludeFromCodeCoverage attribute.

The line of code that shows the "not covered by unit tests" is an anonymous function call

image

Using coverlet.collector version 3.1.2and NUnit 3.13.2

MarcoRossignoli commented 2 years ago

The following block of code is showing as not included by Unit Tests even the method has the ExcludeFromCodeCoverage attribute.

@nics71 did you nean as included ?Because the exclusion is the expected behavior.

nics71 commented 2 years ago

to clarify, line 113 is showing as not covered by a unit test even though the whole block of code is marked as exclude from code coverage. Line 113 is not being excluded as per the attribute

MarcoRossignoli commented 2 years ago

Can you provide a simple repro?

nics71 commented 2 years ago

Hi @MarcoRossignoli,

Creating a new method within the same class still gave the red line down the left hand side, it didn't show up in the Fine Code Coverage report as requiring a unit test but did show up in our SonarQube report as "not covered by a unit test"

However, refactoring the method to a new class and marking the method with the attribute, removed the red line, also didn't show up in FCC and was also excluded within SonarQube so happy to go with this option