How to ignore code blocks in sonar code coverage analysis?

There are quite a few such fragments in our code:

if(logger.isDebugEnabled()) { logger.debug("...") } 

Is it possible to configure SonarQube so that such code blocks are not included in code coverage analysis? Writing tests to cover such debugging statements doesn't seem to make much sense ...

I found out how:

  • ignore entire files from coverage analysis
  • ignore problems in code blocks

But I did not find a way to exclude a code block from coverage analysis.

+5
source share
1 answer

I also had the same problem. Ignoring this, I used the following two methods:

1) Mock The Logger Using any example of the Mocking Framework Mockito, Powermockito, PowerMock, etc. Use the same mocking code in test classes where applicable

2) Save logback-test.xml (or register the configuration file for any logging structure used) in the class path and set the lower level of the log as Trace.So allow test classes to load a logger to print these instructions.

This will help in demonstrating the details of how test cases run with operator instructions.

0
source

All Articles