I have a set of .Net projects with a couple of test projects. I ran a build and from VSTS build i see that my Lines covered % is 45.24(8213/18153) but when i see the same from SonarQube, it shows me 13.3%(361/2717). I'm wondering how does sonar display different metrics compared to VSTS. Also the number of binaries analyzed in code coverage differes from VST to SonarQube. Is this expected?
- SonarQube version: 6.7.1, Community Edition
- SonarC# version: 6.8.2(build 4717)
- SonarQube VSTS task version : 3.2.0(4.1 version doesn't work at all)
- SonarScanner for MSBuild: 4.1
- Solution Version: VS 2015
- VSTest Console.exe version: 14.0.25420.1
Please let me know if any further details would be required to investigate further.
The difference in the numbers is most likely caused by SonarC#'s calculation of Executable Lines. It is explained in detail in this blog post.
In brief: Executable Lines counts are fed into the coverage denominator for files not represented in your coverage report. Native tools simply ignore their existence when calculating that percentage. Your coverage number is lower in SonarQube because it's taking all your files into account.
Addendum: My answer is (correct and) language-agnostic. duncanp's answer is MSDN-specific and thus likely more relevant in this context.