Sonarcloud says I have 0% Code coverage even though I wrote unit tests

I am using SonarCloud with GitHub Actions. I turned it on last night and was resolving bugs today. When I pushed a branch and did a PR it failed because there are no new unit tests. I in fact made unit tests and there are other unit tests in the project, but none of them are getting recognized. I am just using the default settings given for setting up SonarCloud with GitHubActions. Did I not configure something? Any help would be appreciated.

Hi Doug. Welcome to the community!

SonarCloud does not automatically run your tests or compile coverage reports itself. It has to import those reports from a coverage analysis that you set up separately. In your case (a Java project) you would use the Jacoco library and the associated Jacoco maven plugin.

For details, have a look here:

Oh hey thanks, I figured that out eventually. Just saw you replied. I had found those articles but they didn’t help completely. After digging around, I found that I had to pass the following in the Actions yaml file: mvn -B org.jacoco:jacoco-maven-plugin:prepare-agent verify org.jacoco:jacoco-maven-plugin:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

For some reason every help file I found assumed either I knew that, or that just putting the info in the pom file would make them execute. Maybe I’m missing something, but that command made it work for me so I’m posting it here for anyone who comes after me.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.