SonarQube "Coverage on New Code" below threshold in CI
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.
QUALITY GATE STATUS: FAILED
0.0% Coverage on New Code (required >= 80.0%)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.
pytest --cov=src --cov-report=xml
sonar-scanner -Dsonar.python.coverage.reportPaths=coverage.xmlAdd tests for the changed lines
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.