In our source code we excluded some methods from CodeCoverage with the ExcludedFromCodeCoverage attribute. These methods only call other classes through there interfaces, so there is no logic in them.
However SonarCloud doesn’t recognize the ExcludedFromCodeCoverage attribute and causes our Quality gate to fail on the rule 30% CodeCoverage on new lines of Code.
How do we solve this, or is this a bug in SonarCloud?
Could you please read the discussion in sonar-dotnet issue #1421 and see if it’s related? In short, our plugin works at file-level exclusions, and you’ll need to use your code coverage tool exclusion mechanism to do that at more granular level - see this answer from the #1421 thread.
The issue you mention is quit related, the only difference is that the use OpenCover for there analysis, while we use the Visual Studio test task in Azure DevOps. I will futher investigate why these results ignore or not handle the ExcludedFromCodeCoverage attribute correctly.
We see that it is excluded with the “vs test runner”, but the code in de results is marked as 0% covered, which results back to SonarCloud Code Coverage results and the you don’t pass the quality gate coverage.
Hi @DVB - I added the [ExcludeFromCodeCoverage] attribute to some of our files as well and the SonarCloud analysis correctly excludes those files from code coverage