C# ExcludeFromCodeCoverage on method scope not working

  • versions used: SonarQube 8.4.1
  • steps to reproduce
    Place ExcludeFromCodeCoverage above a method instead of above a class

Works:

[ExcludeFromCodeCoverage]
public class Foo 
{
    public void Bar()
    {
    }
}

Does not work:

public class Foo 
{
    [ExcludeFromCodeCoverage]
    public void Bar()
    {
    }
}

Anyone?

hi @Rouke.Broersma.IS. This has been discussed in this github issue:.

In short: please use the code coverage tool exclusion mechanisms when running the code coverage tool. If the coverage report will contain the entry, then our plugin will parse it and upload it to SonarQube.

I had found that issue but since we do not use coverlet and the excludefromcodecoverage attribute docs say that it works on method scope I assumed microsoft would honor their own attribute in their code coverage tooling… Apparently not. Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.