Sonar Cloud - How to ignore getter and setter methods from code coverage Uncovered Lines

Template for a good new topic, formatted with Markdown:

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps) - Azure DevOps
  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI - Azure DevOps
  • Scanner command used when applicable (private details masked)
  • Languages of the repository - csharp
  • Only if the SonarCloud project is public, the URL
    • And if you need help with pull request decoration, then the URL to the PR too
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
  • Steps to reproduce
    Problem: How to ignore getter and setter methods from code coverage Uncovered Lines
    Steps - Code coverage is showing Uncovered Lines for Getter, Setter methods, variables, try and catch blocks, if blocks, constructor, variables assignment types of codes. Sonar cloud shows red in code coverage as its Uncovered Lines.
  • Potential workaround - Dont know. Help need if any workaround options/code/logic to ignore these cases from the code coverage.

Any assistance you can provide would be greatly appreciated.

1 Like

Any assistance you can provide would be greatly appreciated.

Should the below configuration will help to ignore the getter and setter methods from sonar code coverage. Please confirm.

<!–Exclude Auto-Properties–>
<Functions>
<Exclude>
<Function>.get_.</Function>
<Function>.set_.</Function>
</Exclude>
</Functions>

Any assistance you can provide would be greatly appreciated.

Hello @supravat.samanta

You can use the ExcludeFromCodeCoverage attribute to exclude parts of the code that you do not want to be part of the code coverage information.