How SonarQube code coverage reporting works
Blog post from Sonar
SonarQube relies on external tools like JaCoCo, coverage.py, and Istanbul to import code coverage data, focusing on how much of the codebase is exercised by tests rather than generating the data itself. Coverage issues often arise during the four-stage pipeline of test execution, coverage recording, report generation, and data upload to SonarQube, with failures typically occurring at handoff points due to missing or improperly formatted reports, incorrect scanner configurations, or mismatched file paths. Discrepancies between coverage tools and SonarQube are due to different interpretations of "coverable lines" and scope differences, as SonarQube includes all project files, not just those tested. SonarQube also highlights test quality issues, flagging tests with no assertions, unreachable assertions, and empty test classes, which traditional coverage metrics may miss. Understanding these intricacies allows developers to diagnose and resolve coverage issues efficiently, ensuring a more accurate representation of code quality and test effectiveness.