Need help figuring out why AZD code coverage % and SonarCloud code coverage %'s differ

We have a C# code base built in Azure DevOps, linked with SonarCloud. We’ve gotten the tests integrated correctly and things show up in SonarCloud correctly, except the code coverage. The % in AZD shows up as something like 85% with Cobertura, but when looking at the % in SonarCloud, it only shows 0.7%.

The SonarCloudAnalyze@1 log (attached) looks like it sees the .coveragexml file
SonarCloudAnalyze.txt (248.7 KB)

Here is my pipeline .yml file.
azd.yml.txt (2.2 KB)

Is there a setting or something I need to set in SonarCloud?

Hey there.

2021-11-24T15:08:50.9063127Z INFO: 129 files indexed
2021-11-24T15:08:50.9063614Z INFO: 831 files ignored because of inclusion/exclusion patterns
.....
2021-11-24T15:09:15.6688037Z INFO: Sensor C# Tests Coverage Report Import [csharp]
2021-11-24T15:09:15.6689076Z INFO: Parsing the Visual Studio coverage XML report D:\a\1\TestResults\VssAdministrator_fv-az75-890_2021-11-24_15_05_00\In\fv-az75-890\VssAdministrator_fv-az75-890_2021-11-24.15_04_44.coveragexml
2021-11-24T15:09:15.8072234Z INFO: Adding this code coverage report to the cache for later reuse: D:\a\1\TestResults\VssAdministrator_fv-az75-890_2021-11-24_15_05_00\In\fv-az75-890\VssAdministrator_fv-az75-890_2021-11-24.15_04_44.coveragexml
2021-11-24T15:09:15.8352023Z INFO: Coverage Report Statistics: 23 files, 15 main files, 15 main files with coverage, 8 test files, 0 project excluded files, 0 other language files.
2021-11-24T15:09:15.8353734Z INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=156ms

It does seem like the figures reported here (23 files, 15 files with coverage, 8 test files…) does fall short of your 129 files indexed.

What I would recommend is that you start by:

  • narrowing it down to one specific file where there is coverage reported in your Cobertura report but not in SonarCloud
  • check if there are files represented in your Cobertura report (where coverage is being reported) that don’t show up in SonarCloud
  • check if there are files showing up in SonarCloud (with no coverage reported) that aren’t in your Cobertura report
1 Like

Thank you very much for the response. Your suggestions were spot-on. As it turns out, these were integration tests, not unit tests. As such, the logic was only consuming the interfaces, not the implementation, so it’d make sense that a lot of the files didn’t appear to be touched.

1 Like