Sonarqube does not seem to be scanning unit tests properly

Sonarqube (10.1) does not seem to be scanning unit tests properly. The Unit tests cover all of the business logic, but Sonar is showing 0


Hi Kevin,

Been fighting with test coverage recently, too. Advice - go back to basics. Take you unit testing tool report, and check if:

  • tests you think should run, have actually ran
  • this is reflected in your unit testing framework report, and you can see in the report, that methods you think should have been visited, were actually visited

Once you can answer both as - yes - and test are run, methods are reported visited - look inside your test output coverage report, and find if report reflects what you have seen above.

There is no easy way to debug this, no silver bullets, no one-look epiphanies. There are so many moving parts along the way, and sometimes answer is buried in a single, specific line of 250k-lines log file. Talking from personal experience, unfortunately…

Kind regards,
Michal Gruda

A good place to start can also be to see whether or not your coverage report is being found by the scanner at all.

And since it looks like a Java project, I’ll leave the documentation here on Java Test Coverage in case you haven’t seen it.