Skip to content
Latchkey

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.

sonar-scanner
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

  1. Run your test suite with coverage enabled first, producing an XML report.
  2. Set the language-specific report path so the scanner imports it.
  3. Confirm the scan log shows the coverage report was parsed.
Terminal
pytest --cov=src --cov-report=xml
sonar-scanner -Dsonar.python.coverage.reportPaths=coverage.xml

Add 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.

Frequently asked questions

What causes ""Coverage on New Code (required >= 80%)""?
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 "Coverage on New Code (required >= 80%)"?
Generate coverage before the scanner, then point Sonar at it

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card