SonarQube shows 0% coverage even though tests run. How do you fix it?
IntermediateTroubleshootingSonarQube
Answer
Short answer
SonarQube doesn't run tests — it only imports a coverage report. 0% means the report wasn't generated, was in the wrong format, or the scanner wasn't told the path. Generate the report before the scan and set the correct property.
Checklist by language
| Language | Report | Property |
|---|---|---|
| Java (Maven) | JaCoCo XML target/site/jacoco/jacoco.xml |
sonar.coverage.jacoco.xmlReportPaths (auto-detected at default path) |
| JS/TS | coverage/lcov.info (jest --coverage) |
sonar.javascript.lcov.reportPaths |
| Python | coverage.xml (pytest --cov --cov-report=xml) |
sonar.python.coverage.reportPaths |
| .NET | OpenCover / Cobertura (coverlet) | sonar.cs.opencover.reportsPaths |
| Go | coverage.out |
sonar.go.coverage.reportPaths |
Other causes
- Scan ran before tests, or in a different job/container where the file doesn't exist (pass it as an artifact).
- Path mismatch — the report has absolute paths from another container (common in Docker/monorepos); fix with relative paths or
sonar.projectBaseDir. - Files excluded by
sonar.coverage.exclusions. - The scanner log shows a warning like "No coverage report can be found" — read it.
What to say in the interview
"SonarQube only imports coverage, so I make sure tests produce the report before the scan, in the same workspace, and set the right report-path property for the language. Then I check the scanner log for 'report not found' or path-mismatch warnings."
More on SonarQube
What is SonarQube and how do you integrate it into a pipeline?BeginnerWhat does SonarQube analyse?BeginnerHow do you run SonarQube locally with Docker?BeginnerHow do you scan a project with sonar-scanner?BeginnerHow do you run SonarQube analysis for a Maven project?BeginnerWhat is a quality gate in SonarQube?Beginner