Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify methods to be skipped by Sonar when counting coverage?

I am using sonar for code analysis in my current project and my question is how can I specify certain methods, particularly getters and setters to be excluded when counting code coverage.

Also I realized that for the @Component and @Value annotations the line coverage is 0, even when there is a unit test which uses the specific bean. Interestingly, the @Autowired is skipped as it should be.

Where can I change this configuration/add some exceptions?

like image 670
abalogh Avatar asked Feb 24 '12 09:02

abalogh


People also ask

How does the SonarQube code coverage scan work?

To scan a specific codebase you run the SonarQube scanner. This is a local process that analyses your code then sends reports to the SonarQube server. The code coverage metric has to be computed outside of SonarQube using a different tool. The result is then ingested into SonarQube and shown within its web interface.

What code quality metrics can I import into SonarQube?

Test coverage reports and test execution reports are important code quality metrics that you can import into SonarQube. Test coverage reports tell you the percentage of your code that is covered by your test cases.

How do I exclude files from SonarQube checks?

Sometimes, an analyzed project may contain some generated code that we want to exclude and narrow the focus of SonarQube checks. Let's exclude our class by defining sonar.exclusions in our pom.xml: In that case, we've excluded a single file by its name. Checks will be performed for all files except that one. We can also use file matching patterns.

How do I get test execution reports from SonarQube?

Test execution reports tell you which tests have been run and their results. SonarQube doesn't run your tests or generate reports. To include coverage results in your analysis, you need to set up a third-party coverage tool to generate reports and configure SonarQube to import those reports.


1 Answers

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). You can try all those different tools to see which one gives you the best results. FYI, Jacoco will soon be the default coverage tool for Sonar.

like image 144
Fabrice - SonarSource Team Avatar answered Nov 18 '22 10:11

Fabrice - SonarSource Team