In our code, there are quite a lot of logging fragments like this:
if(logger.isDebugEnabled()) {
logger.debug("...")
}
Is it possible to configure SonarQube so that such code blocks are not included in the code coverage analysis? Writing tests to cover such debug statements does not seem to make much sense...
I found out how to:
But I did not find a way of excluding a code block from the coverage analysis only.
Since Sonarqube can import JaCoCo coverage report, you could use an annotation containing "Generated
" in its name, as explained here by nineninesevenfour.
In your case, you would replace your log calls with logDebug()
calls, and:
@Generated
void logDebug(String message) {
if(logger.isDebugEnabled()) {
logger.debug("...")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With