Skip code from coverage

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve Skip some code from coverage. If i have a code where we have if block, else block and multiple catch blocks, can i skip multiple catch testing as part of my code coverage? I dont want to spend too much time on writing junits
  • what have you tried so far to achieve this

Hello @Chakshu_M,

Welcome to SonarSource community forum :slight_smile:.

First of all I would like to highlight that you run an End of Life version of SonarQube (7.4). I strongly encourage you to upgrade to 7.9.x (our LTS, Long Term Support version) or the latest and greatest which is 8.4 as of today (8.5 coming end of September)

About your question: It’s not possible to ignore the lack of coverage per block of code. The highest granularity is per file (ie you can ignore lack of coverage on some files, and obviously only if obviously you have a good reason to do so.

Now, you may not have a real problem: It is not required, not even recommended to try to cover 100% of your code.
The default Sonar Way quality gate, which is our recommended in the absence of strong user views on what should be the quality gate, is a good example. It requires 80% (on new code) and that’s already a lot. Some organizations (ie your whole company or subteams with high maturity in terms of unit tests and test coverage) may wish to go beyond this and aim at 85 or 90%, but we don’t think it’s reasonable or useful to shoot for more.
So it could be completely OK to leave a certain number of exception cases uncovered.

Does that make sense ?