Code coverage check in Quality Gate for PR not honoring [ExcludeFromCodeCoverage] attribute

I’m using SonarCloud and have created a PR on my source code which it has analyzed. It returns that I have added 36 lines of code (none of which are covered) and that it fails the Coverage rule of my quality gate. However, the code are all changes to a C# class that is decorated with the [ExcludeFromCodeCoverage] attribute, and this works on other similar projects. As far as I can see there are no relevant differences between the projects.

My questions:

  • Should the SonarCloud coverage honor this attribute?
  • If so, what might be different between the projects that it is ignored in one, and correctly regarded in another project?

Ok, I accidentally stumbled on the answer to my own questing. The project with the error had a custom .runsettings file for the unit tests. This configured the code coverage settings differently than the other projects. Somehow this probably had an effect on the report sent to SonarCloud regarding the code coverage.

1 Like