SonarCloud does not show all the coverage of the coverage.xml file

We have a pipeline in Azure Devops where, in addition to compiling, test cases are executed and their coverage is obtained. In the coverage.xml file there are some parts where it says coverage=yes but then it doesn’t appear in SonarCloud.

Example:
This is a fragment of the coverage.xml file where it can be seen that this line of code is covered

<function block_coverage="100.00" line_coverage="100.00" blocks_covered="3" blocks_not_covered="0" lines_covered="3" lines_partially_covered="0" lines_not_covered="0" id="8796" token="0x6000013" name="AddAzureStorage(Microsoft.Extensions.DependencyInjection.IServiceCollection, string, string)" namespace="XXXX.Core.Files.AzureStorage" type_name="AzureStorageExtension">
          <ranges>
            <range start_line="9" start_column="9" end_line="9" end_column="10" covered="yes" source_id="2" />
            <range start_line="10" start_column="13" end_line="10" end_column="133" covered="yes" source_id="2" />
            <range start_line="11" start_column="9" end_line="11" end_column="10" covered="yes" source_id="2" />
          </ranges>
        </function>

If we see the HTML generated by an external tool it also appears covered

But instead, in SonarCloud it does not appear in green cover.

Why? Why in SonarCloud some blocks yes and others no if in the coverage.xml file is correct?

Thanks!!
Regards

Hey there.

Stepping back a bit…

  • Do you see that files in the x.Core.Files.AzureStorage have Lines of Code in the Code tab of your project, or is there a -?
  • Are there any exclusions set (such as sonar.coverage.exclusions that could prevent the coverage from being reported)?

Hi,

Only have two exclusions file but are json files of configuration.

But in code tab, the same modules that not have coverage either have lines of Code, so the error could be here.

This is a error in project compilation or where?

Thanks.

What do your analysis logs say about the import of code coverage?

Hi,

The information that show the logs is the following:

INFO: Sensor C# Tests Coverage Report Import [csharp]
INFO: Parsing the Visual Studio coverage XML report /agent/_work/1/a/coverage/coverage.xml
INFO: Adding this code coverage report to the cache for later reuse: /agent/_work/1/a/coverage/coverage.xml
INFO: Coverage Report Statistics: 340 files, 238 main files, 238 main files with coverage, 102 test files, 0 project excluded files, 0 other language files.
INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=1101ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=14ms

I think the information in the coverage file is correct, but it doesn’t show all the coverage because possibly the compilation of the project is not complete and that’s why it appears - in the Code tab under the Lines of code column.

Regards