I am using sonarcloud analysis in my java project with gradle. I want to exclude some files/folders from codecoverage (dtos, etc.). In gradle I defined following exlusion:
But when I open project in sonarcloud, not all files/folders are excluded from code coverage analysis. As you could see in screenshot below, only folder dtos was excluded, but based on the definition of coverage exclusions also config and configuration should be excluded.
Same goes for the content of config folder, based on the definition of coverage exclusions all files inside should be excluded, but for some reason one file isn`t (see screenshot below).
Does the same happen if you leave only **/config in the exclusions (without others '**/configuration', '**dtos' etc.)? You could also try with **/config/** instead of only **/config.
Can you also try without the quotes: ' in the exclusions property?
thanks for the response. Removing ' helped, now specified folders/files are removed from code coverage, but reported coverage is still pretty low. Sonarcloud reports 41.9% coverage of lines of code, but jacoco reports 58.9% - I assumed that sonar just picks jacoco .xml reports and shows same coverage as jacoco. Any ideas why the reported numbers are different?
You can find out details about how coverage is calculated in SonarCloud here: SonarCloud . Although the data is taken from the Jacoco, Sonarcloud calculates the ‘Coverage’ according to the formula mentioned in the link.
Coverage ( coverage )
It is a mix of Line coverage and Condition coverage. Its goal is to provide an even more accurate answer to the following question: How much of the source code has been covered by the unit tests?
Coverage = (CT + CF + LC)/(2*B + EL)
where
CT = conditions that have been evaluated to ‘true’ at least once
CF = conditions that have been evaluated to ‘false’ at least once