SonarQube "Coverage on New Code" below threshold in CI
By Kaveh Alemi·Latchkey
The quality gate measures coverage only on lines you changed. It fails either because those lines really lack tests, or because no coverage report was imported so Sonar sees 0% on new code.
What this error means
The gate reports a failing "Coverage on New Code" condition, often "0.0% Coverage on New Code (required >= 80%)" when the report path is wrong, or a real low number when tests are missing.
sonar-scanner
QUALITY GATE STATUS: FAILED
0.0% Coverage on New Code (required >= 80.0%)
Diagnose it: did the report reach the service?
Coverage and quality integrations fail in two distinct places: the report was never produced, or it was produced and the upload was rejected. Establish which before touching tokens.
Terminal
# 1. does the report exist and is it non-empty?
ls -la coverage/ && head -5 coverage/lcov.info
# 2. does it reference paths the service can map to the repo?
grep "^SF:" coverage/lcov.info | head -5
# 3. did the upload actually succeed, or just not fail the step?# most uploaders exit 0 on a rejected upload unless told otherwise
Common causes
The coverage report was not generated before the scan
If tests did not run, or ran after the scanner, there is no report to import, so Sonar records 0% coverage on new code.
The report path property points to the wrong file
A wrong sonar.python.coverage.reportPaths (or the language equivalent) means Sonar finds no coverage data and treats new lines as uncovered.
How to fix it
Generate coverage before the scanner, then point Sonar at it
Run your test suite with coverage enabled first, producing an XML report.
Set the language-specific report path so the scanner imports it.
Confirm the scan log shows the coverage report was parsed.
When coverage data imports correctly but the number is genuinely low, add tests that exercise the new or modified code paths until new-code coverage clears the threshold.
How to prevent it
Always run tests with coverage before the scanner step, not after.
Pin the coverage report path in a committed config so it cannot drift.
Treat new-code coverage as a first-class part of every change.
Frequently asked questions
What causes SonarQube "Coverage on new Code" below threshold in CI?
There are 2 common causes: the coverage report was not generated before the scan and the report path property points to the wrong file. If tests did not run, or ran after the scanner, there is no report to import, so Sonar records 0% coverage on new code.
How do I fix SonarQube "Coverage on new Code" below threshold in CI?
There are 2 fixes depending on which cause you have: generate coverage before the scanner, then point sonar at it and add tests for the changed lines. Work through them in order, since the first is the most common.
What does SonarQube "Coverage on new Code" below threshold in CI actually mean?
The gate reports a failing "Coverage on New Code" condition, often "0.0% Coverage on New Code (required >= 80%)" when the report path is wrong, or a real low number when tests are missing.
How do I stop SonarQube "Coverage on new Code" below threshold in CI happening again?
Always run tests with coverage before the scanner step, not after. The prevention section lists 3 changes that keep it from recurring.