How to Make Sonar Ignore Some Classes for Codecoverage Metric

SonarQube code coverage - exclude some classes

Try to use sonar.coverage.exclusions.

As sonar.coverage.exclusions is Comma-delimited list of file path patterns to be excluded from coverage calculations. Your pattern should be like this:

sonar.coverage.exclusions=com/abc/demo/presentation/beans/**/*, com/abc/demo/presentation/interfaces/**/*, com/abc/demo/presentation/validator/**/*, com/abc/utility/**/*

Note: Documentation for this option was removed in 7.3 (Google: site:docs.sonarqube.org "sonar.coverage.exclusions"). But you can still see them when you open the administration pages for the project on Sonar -> "General Settings" -> "Analysis Scope". Look for the values after "Key:"

How to specify methods to be skipped by Sonar when counting 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). 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.

Coverage Exclusions and Source file Exclusions

Changes are not immediately taken into account. A new analysis should be triggered.

Sonar Jacoco Excludes sonar.jacoco.excludes causes 0% coverage instead of ignored.

Common pitfall to use the wrong pattern to exclude. Notice the .

Bad :

<sonar.jacoco.excludes>*.model.*</sonar.jacoco.excludes>

Good:

<sonar.jacoco.excludes>*model*</sonar.jacoco.excludes>

Documentation for weary travellers.



Related Topics



Leave a reply



Submit