Not generate coverage in SonarCloud

I have a sample .Net Framework project that I would like to be able to see the coverage in SonarCloud using vstests. I have tried several combinations but I do not get the correct result.

Looking at the official documentation (.NET Test Coverage | SonarCloud Docs) I see that it is not necessary in the preparation of sonarcloud indicate the property or point to the generated coverage file, since it does it automatically if it is Windows-latest (but if I add sonar.cs.vscoveragexml.reportsPaths=“$(Agent.TempDirectory)\TestResults***.coveragexml” doesn’t work either) and you also have to add --collect “Code coverage”. I haven’t added the latter to my .yml file since I don’t know how to add it, but adding the Code Coverage enabled check I think is enough.

Also, in the SonarCloud Analyze log, it seems that it is taking coverage, but then in SonarCloud it appears 0.0%

INFO: Parsing the Visual Studio coverage XML report D:\a\_temp\TestResults\37670d3b-7516-4b7d-98e0-cc95fc087d75\VssAdministrator_fv-az290-59_2022-07-10.10_43_34.coveragexml
INFO: Adding this code coverage report to the cache for later reuse: D:\a\_temp\TestResults\37670d3b-7516-4b7d-98e0-cc95fc087d75\VssAdministrator_fv-az290-59_2022-07-10.10_43_34.coveragexml

What is happening to me?

This is my yml:

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'SonarCloud'
    organization: 'example'
    scannerMode: 'MSBuild'
    projectKey: 'example'
    projectName: 'example'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: 'HolaMundoTests/bin/Debug/netcoreapp3.1/HolaMundoTests.dll'
    searchFolder: '$(System.DefaultWorkingDirectory)'
    codeCoverageEnabled: true
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: SonarCloudAnalyze@1

Hey there.

I would suggest two things:

  • Check the actual D:\a_temp\TestResults\37670d3b-7516-4b7d-98e0-cc95fc087d75\VssAdministrator_fv-az290-59_2022-07-10.10_43_34.coveragexml file – does it indicate that files/lines are being covered by tests?
  • There should be some additional logging about coverage at a DEBUG level (setting sonar.verbose=true that might reveal where the issue is

Hello

Thanks for the quick reply.

I am attaching two files, the coverage file generated in the pipeline and the SonarQubeAnalyze task log after adding sonar.verbsose=true as you requested.

In principle, the coverage file seems correct, but in the log I was surprised by this…

2022-07-11T11:48:27.1944974Z 11:48:27.193 INFO: Adding this code coverage report to the cache for later reuse: D:\a\_temp\TestResults\3017ee59-41cf-46a3-abd5-c24084d62859\VssAdministrator_WIN-HOEUFJN5B3L_2022-07-11.11_47_35.coveragexml
2022-07-11T11:48:27.1946184Z 11:48:27.194 DEBUG: Analyzing coverage after aggregate found '0' coverage files.
2022-07-11T11:48:27.1946861Z 11:48:27.194 DEBUG: The total number of file count statistics is '0'.

What does this mean?

SonarQubeAnalyzeLog.txt (3.2 MB)
VssAdministrator_WIN-HOEUFJN5B3L_2022-07-11.11_47_35.zip (895 Bytes)

Hi Colin,

I have already managed to solve the error and I already see the coverage in SonarCloud.

In the yml when I run the tests I refer to a file that is uploaded to the git repository bin/Degub/* by mistake instead of the file that is generated in the compilation (bin/Release/*)

Change this in the yml it works correctly

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: 'HolaMundoTests/bin/$(buildConfiguration)/netcoreapp3.1/HolaMundoTests.dll'
    searchFolder: '$(System.DefaultWorkingDirectory)'
    codeCoverageEnabled: true
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.