The sonarqube scan is showing significantly lower test coverage for files that was not changed

The situation:

  1. We have a nightly job that collects code coverage from the master / main branch!

  2. At morning someone is merging PR to master with 86% coverage (is means that some files will have low coverage, but generally it enough)

file1.tsx // 100%
file2.tsx // 90%
file3.tsx // 70%
//            total: 86%
  1. Then other developer create a new PR

git history:

commit2 # morning merge (the PR with 86% coverage)
commit1 # nightly job used this commit to collect coverage
commitC
commitB
commitA

PROBLEM

  • if developer will use commit1 as base for branch no issue, coverage for new files fill be correct !

  • BUT if he/she will use commit2 then sonarqube fail and report:

    • that file2.tsx & file3.tsx is a new files with low coverage, even I developer don’t touch them

How fix this behavior ?

Hi,

Welcome to the community!

It’s not clear to me which direction your stack of commits goes in. Is commit2 the latest? But this sounds like a question of your New Code definition. How have you defined it?

 
Ann