SonarQube new-code baselines and coverage evidence: explain a changed quality gate
Explain how new-code definitions and coverage reports affect SonarQube quality measures. Diagnose a gate change without silently redefining the reviewed population.
TL;DR: A quality-gate comparison needs the same analysis scope, new-code definition and coverage inputs. Inspect those before changing a threshold. Moving the baseline can change which code is measured without improving any code or tests.
New code is a configured population
SonarQube distinguishes measures on new code from measures on the overall codebase. Depending on product/version and analysis context, new code can be defined using a previous version, a time period, a specific analysis or a reference branch. Pull-request analysis uses its change context rather than every branch-level assumption.
SonarSource describes these modes in quality standards and new code. Record the effective definition and relevant revision when comparing analyses. A policy change is legitimate when reviewed; silently changing the population to make a failing result green is not evidence of repair.
Work the denominator before the threshold
Use an illustrative line-only calculation to practice the scope decision. Analysis A includes 20 new executable lines with 16 covered, or 80%. Analysis B includes 40 with the same 16 covered, or 40%. That difference can arise from changed scope or additional uncovered code; the percentages alone do not establish which.
SonarQube's actual coverage measures can include conditions/branches as defined for the language and metric, so the simple line fraction is not a replacement for the product's metric definition. Inspect the reported uncovered lines and conditions together with the imported coverage report.
| Change to inspect | Possible effect | Evidence required |
|---|---|---|
| New-code baseline | Different measured population | Effective definition and baseline revision |
| Analysis exclusions | Files disappear from scope | Reviewed exclusions and file inventory |
| Missing coverage report | Coverage evidence absent | Test output, report path and scanner import logs |
| Different source/report revisions | Misaligned evidence | Commit and build identity for both |
A scanner does not invent test execution
For languages where coverage is imported, the test tool produces a report and the scanner consumes it through the supported configuration. Tests passing without a report at the expected path cannot establish measured coverage. A report generated before the current checkout can be equally misleading.
Verify that the relevant tests ran, the report exists, its format/path matches the scanner configuration and scanner logs confirm import. Compare a known newly covered line with the server result. Product support, branch analysis and decoration capabilities depend on edition and version; document the deployed combination when reproducing an issue.
If a reference branch changes, ensure the analysis has the SCM information needed for the chosen comparison. Do not assume a shallow or incomplete checkout supplies every relevant history fact. Follow the scanner's documented requirements for that setup.
Self-check: a failing new-code gate becomes green after resetting the baseline, with no source or test changes. What was improved? The reported population changed; no code improvement has been demonstrated. Review whether the policy change was intended and preserve the original finding.
Try the missing coverage report and keep analysis identity attached to gate enforcement.
SonarQube imports coverage produced by external tools; see the coverage workflow for generation and import requirements.