Creating Incremental Coverage Report

Hi All :slight_smile: ,
We are scanning a large codebase with multiple submodules using SonarQube. Since running all the tests for the entire project takes a lot of time, we would like to explore the option of running only the relevant tests per MR and save time. The issue is that we won’t have the accurate coverage data transmitted to SonarQube, and the quality gate will fail.

My question being, is there a way to create an incremental Coverage report in SonarQube such that Sonar Scanner will report the coverage based on the files that were actually chnaged and won’t harm the overall coverage of the code base?

Relevant information about our setup:

  • We are using GitLab for version control and CI.
  • We are using the Developer edition, on-prem setup.
  • The repo is written in C++, scanned using cfamily with g++ & gcc compilers.
  • Sonar version: Developer Edition v2025.2

Please let me know if you need any further information, I will gladly share it.

Thank you very much in advance :slight_smile:

Hi,

Welcome to the community!

Will it?

PR/MR Quality Gates only apply conditions on new code, so it should only be looking at whether your changes are adequately tested. If you can isolate the tests you want to run, this ought to work. The hard part is this

I.e. running only the tests relevant to your changes. And that’s going to happen on your side, before analysis takes place. It’s not clear to me that we can help with that part.

 
Ann

Hi Ann,

Thank you very much for your reply and assistance on this matter :slight_smile: .

The help requested is mostly on whether what I’m trying to do is possible or not, and based on your answer, I think I got what I was looking for, but I would like to verify I got it right if I may.

  1. If we run a scan on a PR/MR, the Quality gate will check coverage only on new lines, and if they are covered based on the tests that were reported in the coverage report, this will not degrade the overall coverage of the scan.
  2. The overall coverage can be updated based on “Full scans” such as scheduled runs, that will run on all the tests.

I appreciate your assistance,
Kuper

Hi Kuper,

To be honest, we’re in uncharted territory here, but this is the way it should work. :sweat_smile:

Yes!

 
HTH,
Ann

Got it,

I will run tests, and I will update this thread with the results for future reference, thanks again for the assistance and the support.

All the best,
Kuper :slight_smile:

1 Like