Quality Gate Shows Pass even if even if Code coverage condition set in Quality gate is not met

*sonarqube- - community edition
I am trying to verify code coverage conditions on Quality gate. Currently the project has tests that shows 27.6 % of code coverage. In Sonar I have setup as Quality Gate fails when code coverage is less than 30%
Sonar still reports this as Passed.
Is there any other setup to be done in admin console or any step missing?


Hi @aa_amwater,

You set the code coverage condition for new code but not at overall code level. This means that a pull request will fail when the coverage is below 30% but the master branch still shows pass.

Therefore, define the code coverage condition for overall code.

1 Like

Thanks Daniel. I did the setup as you mentioned to include overall code level too. Please see attached screenshot. Still it it is showing condition is Passed. Let me know if there is missing here?
I am new with Sonarqube. I will be doing with our licensed developer edition soon.

Thanks !

1 Like

You’ve set the metric to be Condition Coverage instead of Coverage (which is what is displayed on the projects page).

I would bet if you dig into the Measures tab of your project you’ll find that either Condition Coverage isn’t being calculated (I think it’s relatively new that we compute this for C# code, you may need to upgrade to SonarQube v8.3) or is over 30%.

SonarQube reads/computes metrics for both Condition Coverage (also known as Branch Coverage) and Line Coverage. The overall Coverage metric is a mix of these two. Maybe your Line Coverage drags you up above 30% somehow!

Either way – dig into your Measures tab to understand more or change the QG condition to the combined Coverage metric.

Thank you for the information on coverage metric configuration . It worked by adding coverage in Quality Gate.

1 Like