Detection of Coverable Lines

Must-share information (formatted with Markdown):

  • SonarQube 10.5 (89998)
  • how is SonarQube deployed: Docker
  • what are you trying to achieve: I want to get a correct analysis of new code.
  • what have you tried so far to achieve this: I configured SonarQube to use my main branch as reference branch, but it still identifies classes that were not changed in a pull request as New Code.

I have a pull request that changed 359 lines. These lines contain changes in source code and tests files as well as some meta files.
However, in the latest update of the pull request, the coverage was detected to be nothing as SonarQube detected no new lines to cover. SonarQube is configured to detect new code against the main branch.

The changes in the pull request contain several new classes and coverable code. SonarQube even detected coverable code in the analysis before.

My guess is that SonarQube only analyzed only the latest commit which did not have any coverable changes. However, we configured the new code rule to be branch-based in the SonarQube server as well as in the analysis directly:

dotnet sonarscanner begin /k:"..." \
    /"sonarqube" \
    /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml \
    /d:sonar.scm.provider=git \
    /d:sonar.newCode.referenceBranch=main \

dotnet publish -c Release --no-restore my.sln

dotnet-coverage collect 'dotnet test --logger:"junit;LogFilePath=dotnet-test-result.xml"' -f xml -o 'coverage.xml'

dotnet sonarscanner end /d:sonar.token=$SONAR_TOKEN

In the logs, it detected the difference correctly:

INFO: SCM revision ID '487...0b'
INFO: SCM writing changed lines
INFO: Merge base sha1: 743...29
INFO: SCM writing changed lines (done) | time=140ms

How can I get SonarQube to correctly identify the changed files?


Your screenshot shows a PR. What’s considered new code in a PR is based entirely on SCM data and any sonar.newCode.referenceBranch value is entirely irrelevant.

Were there 359 lines changed in the latest commit?

At any rate, I suspect this is about your checkout. The docs may help.


Based on the SCM data, this file is not part of the PR. The 359 lines were changed in multiple commits inside this PR. However, as defined in the docs, any change in the PR is considered New Code. As shown in the screenshot, it does not detect the coverage correctly as the PR contains coverable code and new tests.


Could you share the full analysis log of this PR, as well as a SonarQube screenshot of a “new” line that you believe is coverable?


The log is not available anymore, but here is a screenshot of newly added files with their corresponding tests:

As you can see by the green plus in front of the line, the AssetCacheTests.cs file was ADDED during this PR and should be coverable.


I was looking for a screenshot in SonarQube.

Could you make a small change to force a reanalysis of the PR and provide that log?


Sorry, but the branch is already merged, so no more logs.


What that last screenshot shows is the entire file is marked as ‘new’. This brings us back to the question of your SCM data.

What the first screenshot shows is that every file except the very last seems to be understood by analysis to be a test file. I’m saying that based on the icons. You should review your configuration.


How did you come to this conclusion?



I didn’t find any documentation about which icon has which meaning and there is no other indication about how SonarQube categorizes a file. This should be indicated in the UI.

1 Like

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