Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube code coverage - exclude some classes

Tags:

ant

sonarqube

Is there any way to purposefully increase Code Coverage value in SonarQube by excluding some classes.

like image 240
Krishna Avatar asked Aug 27 '26 14:08

Krishna


2 Answers

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:"

like image 198
Sourav Atta Avatar answered Aug 30 '26 14:08

Sourav Atta


You can exclude certain files in sonar-project.properties file:

sonar.exclusions=**/*.js,**/*.json,**/*.xml,**/*.png,**/*.sh,**/*.h,**/*.m,**/*.c,**/*.cpp,**/*.pdf,**/*.plist,Pods/**/*
sonar.swift.excludedPathsFromCoverage=.*Tests.*

Also, you can include specific files using:

sonar.test.inclusions=**/*Test*/**
sonar.test.inclusions=*.swift
like image 44
Jayprakash Dubey Avatar answered Aug 30 '26 14:08

Jayprakash Dubey