Interview › Security & DevSecOps
How does SonarQube measure code coverage, and does it run your tests? [Basic]
Answer
SonarQube measures code coverage by importing coverage reports generated by test tools. It does not normally run the tests itself; the CI pipeline runs tests and passes reports such as JaCoCo, LCOV, coverage.py, or Cobertura into SonarQube.
Technical explanation
Coverage reflects which lines or branches were exercised by tests, depending on the language and report format.
A missing or misconfigured report can show zero coverage even if tests ran successfully.
Coverage should be used with judgment because high coverage does not prove strong assertions or complete security testing.
Hands-on example
Java example: run mvn test jacoco:report, then run sonar-scanner or mvn sonar:sonar with sonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml. The PR gate checks new-code coverage based on that imported report.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Security & DevSecOps interview questions
- What is technical debt in SonarQube, and how is it estimated? [Basic]
- What is a SonarQube hotspot, and how is it different from a vulnerability? [Basic]
- What metrics does SonarQube track (coverage, duplication, code smells, bugs, vulnerabilities)? [Basic]
- How do you handle false positives in SonarQube? [Basic]
- What does 'clean as you code' mean in SonarQube, and why focus on new code? [Basic]
- What is the difference between a quality gate and a quality profile in SonarQube? [Basic]
- What is the difference between SonarQube and SonarCloud? [Basic]
- What is a SonarQube quality gate, and how do you use it to fail a build? [Basic]