Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube ignore getter/setters in code analysis

Is there a setting in SonarQube dashboard that allows for ignoring getter and setters? This sounds like a better option then coding //nopmd on every method in your codebase.

My codebase has a lot of them and they are dramatically lowering my unit test coverage % being reported in the Sonarqube dashboard

like image 971
George Avatar asked Jan 18 '18 22:01

George


People also ask

How do you exclude getters and setters from code coverage?

With the cobertura-maven-plugin setters and getters can be excluded from code coverage using the ignoreTrivial option.

How do you exclude methods in Sonar code coverage?

There's currently no way to do exclude specific methods from code coverage. For your second case, the problem is not on Sonar side but on the coverage tool that you use (Cobertura by default, but you may have changed it to Jacoco, Emma or Clover).

Are getter methods private?

The reason for declaring the getters and setters private is to make the corresponding part of the object's abstract state (i.e. the values) private. That's largely independent of the decision to use getters and setters or not to hide the implementation types, prevent direct access, etc.

What is the other name of getter methods?

Given this, getters and setters are also known as accessors and mutators, respectively. The getter method returns the value of the attribute.


1 Answers

There is no option to ignore getters and setters. However, if you have classes you'd like omitted entirely from coverage calculations, you can easily do so with exclusions.

like image 50
G. Ann - SonarSource Team Avatar answered Jan 04 '23 06:01

G. Ann - SonarSource Team