Quality Gate has passed while new code is not tested

The Overview tab shows that quality gate has passed, while it should fail if Coverage on New Code is < 70%. The Metrics frame shows “0 new lines to cover” while lots of new lines have been added.


Going into the Measures tab, and into a file where untested code was added:


The new code is clearly identified as Not covered by tests (as displayed when hovering on red bars).

Why doesn’t this new untested code fall into the category New lines to cover ?
What is missing here for the quality gate to fail ?

Using SonarQube version 7.9.5

Hi @Thomas_Collignon, welcome to the SonarSource Community!

It looks like what you’re calling the new code isn’t actually considered new code by SonarQube. What do you see if you expand the “Size” measure in the Measures tab? Are any lines reported as new and does it match your expectation?

You may have a New Code Period setting that isn’t aligning well with your analysis usage.

Hi Jeff,

Size measure is zero. No new line to report.

I thought that what is considered as new code is simply the diff with the branch master, as specified at the top of the frame:


In case it’s linked I also have this warning:



I also find in the doc of short-lived branches that

everything changed in the branch is new code

I would then expect my code to be considered as new code.


Hi Thomas,

Can you clarify which edition of SonarQube you’re running? Looks like it’s Developer Edition possibly.

Now that we know it’s a short-lived branch or Pull Request branch being analyzed, yes, this warning can very much be related to your lack of new code. The state of the local checkout needs to cleanly contain the head revision for the branch (not be in any kind of preview merge state) and also contain the full ref for the target branch. Depending on your CI, it may be possible to specify the checkout behavior to include the ref or you can do it manually with something like:
git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master

1 Like

It’s Community Edition Version 7.9.5 (build 38598).

Thanks for the help, I’ll contact the CI admin (company stuff).

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.