Version note: references describe SonarQube Server 2025.2 behaviour. Check your server, scanner and edition requirements. These examples were not run against a live SonarQube server.
What this guide covers
Coverage compares executed code with code that could be executed. A percentage can change because tests changed, but also because source files, exclusions or the new-code comparison changed.
Before you start
Use one completed analysis and the coverage report produced for the same commit. Compare the same metric: overall coverage and new-code coverage measure different sets of code.
Step 1: Check what the report counts
For a simple line-coverage example, 80 covered lines out of 100 executable lines gives 80 percent. Adding 20 untested executable lines makes it about 67 percent. Some SonarQube coverage measures also include conditions, so line coverage alone may not match the combined value.
Step 2: Compare one file at a time
Record the values for a source file:
Commit / source path:
Producer report and format:
Executable / covered lines:
Conditions / covered conditions:
Analysis exclusions:
Coverage-only exclusions:
New-code boundary and eligible changed lines:
Completed analysis identifier:
Compare these with the producer report. Look for files that never appeared in the report and conditions whose true or false result was never tested.
Step 3: Inspect exclusions and new-code settings
Check analysis exclusions, coverage-only exclusions and the new-code definition. Excluding an untested file can raise the percentage without adding a test. Coverage tools may need an explicit source list to include files tests never import.
Step 4: Add a useful missing test
Choose a real untested behavior, such as a timeout or invalid input. Assert the expected result, rerun tests, regenerate coverage and scan again. Executing a line is not enough if the test never checks its result.
Check the result
The changed percentage should have an identifiable cause in the report and analysis settings. Check the server’s small-change coverage rules before assuming a tiny change must fail a gate.
Conversation
0 commentsNo comments yet. Start the conversation below.