Code Coverage not showing in Sonar Cloud, but does in VSTS build

I am not able to see code coverage in Sonar Cloud. We have a master and develop branch in Sonar Cloud with 0.0% CC. However, in our VSTS build, we see as the build succeeds, 99.92% code coverage for blocks and 99.77% for lines.

Our app is build targeting dotnet Core 2.0 using docker containers on Linux.
Our build runs dotnet core restore, build and test tasks as well as Visual Studio Test task (with code coverage enabled). This allows us to see the code coverage in the VSTS build result, but when we run the tasks to run code analysis and publish to Sonar Cloud, we see the Bugs, Vulnerabilities and Smells accurately but 0.0% coverage. Sonar Cloud also sees the 86 unit tests in the dashboard. Finally the VSTS Build allows us to download the .coverage file.

Are we missing a step to send this to Sonar Cloud? Is there additional parameters we can use to get this to work?

Thanks for your help!

Hi John, maybe you will find some useful information on the following doc page: Code Coverage Results Import (C#, VB.NET). For instance, I see the following warning which might help:

.Net Core
For projects using the roslyn based project system, vstest coverage requires Full to be set on both the unit test projects and the production projects. For more information, please refer to Code coverage requires DebugType full · Issue #800 · microsoft/vstest · GitHub

Thank you! This was the key:

vstest coverage requires Full to be set on both the unit test projects and the production projects

2 Likes

I was seeing the same problem on a Java project, so I needed to run the build and share the xml test coverage reports in Gradle rather than relying solely on github/sonarcloud integration, where I had to provide location of the test coverage reports.