Code coverage with open cover on pull request


We are currently using sonarcloud and github and we would like to do a sonar analysis with coverage of our C# project. We managed to run this analysis with jenkins but we also wanted an analysis every time someone created a new pull request on github.

Since we need exclusion in open-cover we have used the webhooks of github that will launch a custom job in Jenkins with the same settings as a normal sonar analysis.

When using the same settings as the normal analysis but Sonar is saying that the coverage is 0% of all files that are modified by the pull request when a normal analysis shows there is some coverage.

What are we missing?

Thanks you for your time :slight_smile:

Can you give the URL of your project?

The only address I have is this one,, since this a private project I’m not sure how to share it with you.

I took a look and the config looks good. So you need to look at the generated opencover.xml file and check whether it contains the expected information or not. Do you see something special in the logs? Like for instance: on the master branch, the C# coverage sensor take a couple of seconds to execute whereas it takes just a few milliseconds on the PR.

You were right! We had an issue with the way we launched our build, it was in release mode not in debug. Now we have coverage but we don’t have the coverage on only the new code, but on the whole file that was modified.
Is this normal?

Yes, it’s normal :slight_smile:

That’s too bad because when we are analysing the master branch we have a correct assertion of the new code coverage and only the new lines.
Is this feature soon coming to pull requests?

Looks like something was misunderstood. I thought you were asking if it’s normal that you see the coverage of the whole file that was modified. On PR, you do see the coverage of the whole file, but obviously only the coverage of the new lines of those files is taken into account.

So can you clarify what you’re asking?

Sorry if there was a misunderstanding.
Our problem is that when pushing some new code to a PR the sonar analysis doesn’t give the code coverage of the new code only but the code coverage of the whole that is modified.

If you have access to our repo you can check the analysis of the PR 11 on the t1-api project, where there was only a slight modification that was done on the file (that was tested) but sonar count the coverage of the file.

One example of this is the lines from 96 to 114 where there is very old code that is counted toward the coverage percentage.

We’re investigating this Leo.

Hi Leo,

Could you post the logs of the scan of the PR with debug enabled?

Having the scanner logs might help us understand if there is a problem with the scan. Sometimes git repo is not correctly read because of shallow clones or missing branch references. Please let us know once you got them. You can also send it privately if that’s a concern to you.


We’ve done some more test and it seems to be working right now. We’re going to monitor the situation and keep you informed if we have more news.
We can still give you the scanner logs on working scan if you want them.

Thank you for your time

Ok, thanks for the reply.
If you spot a problem again, the best would be to send us the logs of the scan that resulted in unexpected results.