SonarCloud: not showing code coverage for C#?

I have the following pipeline on azure DevOps:

name: $(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.rr)

   - "*"

  vmImage: "ubuntu-latest"

  buildConfiguration: 'Release'

- task: SonarCloudPrepare@1
    SonarCloud: 'SonarCloud'
    organization: 'edenred-ticketbenefits'
    scannerMode: 'MSBuild'
    projectKey: 'Edenred.Utils'
    projectName: 'Edenred.Utils'
    extraProperties: |

- task: DotNetCoreCLI@2
    command: 'restore'
    projects: |
    feedsToUse: 'select'
    vstsFeed: '79f3c258-62f0-41df-9f52-8b916da9e6b8'
    includeNuGetOrg: false
  displayName: 'Restaurando pacotes Nuget'

- task: DotNetCoreCLI@2
  displayName: 'Build da Solucao'
    command: build
    projects: '**/*.sln'
    arguments: '--configuration $(BuildConfiguration) --no-restore'

- task: DotNetCoreCLI@2
  displayName: Test
    command: test
    publishTestResults: true
    projects: '**/Edenred.Utils.Tests.csproj'
    arguments: '--configuration $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=$(Agent.TempDirectory)/TestResults/Coverage/ --collect "Code coverage"'

- task: PublishTestResults@2
  displayName: "Publish Test Results"
    testRunner: 'VSTest'
    testResultsFiles: '$(Agent.TempDirectory)/**.*trx'
    mergeTestResults: true

- task: SonarCloudAnalyze@1

- task: SonarCloudPublish@1
    pollingTimeoutSec: '300'

and I cant get the code coverage on the projects panel…

everything runs ok, no errors are report and yet, the code coverage does not appear… can anyone help?

After setting the path explicitly to “/home/vsts/work/_temp/coverage/coverage.opencover.xml” I can see a message on the logs stating “INFO: Parsing the OpenCover report /home/vsts/work/_temp/coverage/coverage.opencover.xml” which I think was good, but the coverage reported is still zero… there are no others warnings or errors or anything

Using the verbose logging, I was able to capture the message:

DEBUG: Gathering files for wildcardPattern ‘**/coverage.opencover.xml’.
DEBUG: Pattern matcher returns ‘1’ files.
DEBUG: The current user dir is ‘/home/vsts/work/1’.
INFO: Parsing the OpenCover report /home/vsts/work/_temp/TestResults/Coverage/coverage.opencover.xml
INFO: Adding this code coverage report to the cache for later reuse: /home/vsts/work/_temp/TestResults/Coverage/coverage.opencover.xml
DEBUG: Analyzing coverage after aggregate found ‘0’ coverage files.
DEBUG: The total number of file count statistics is ‘0’.

looking at the tests step, I saw:

A total of 1 test files matched the specified pattern.
Results File: /home/vsts/work/_temp/_fv-az52-589_2021-06-23_04_02_15.trx

you see? a coverage file is being generated, apparently, on the wrong path?

Has anyone ever seen something like this?

1 Like

Can you please clarify if this is an analysis of the main branch of the project, or is it a pull request analysis?

If the scanner output shows that the coverage report file was processed, that’s good progress. Next I would look inside the file, to verify that the coverage data about the files you expect is really there or not.

A common error is when the coverage report file references source files that don’t exist in the filesystem. In this case the scanner output should tell you about the missing files. I would also verify that the referenced source files are actually analyzed: browse the Code tab of the project, check that the files are there.

Sorry for the late reply, I’ve been working on getting the code to actually work, lol

but now back to the issue…

The analysis is for the main branch (master) and other branches also, but none show the actual coverage…

on the logs I have also the following entry:

2021-08-04T23:08:17.6296391Z 23:08:17.629 INFO: Parsing the Visual Studio Test Results file ‘/home/vsts/work/_temp/_fv-az105-801_2021-08-04_23_07_15.trx’.
2021-08-04T23:08:17.6782411Z 23:08:17.677 DEBUG: Parsed Visual Studio Test Times - duration: 2696.
2021-08-04T23:08:17.6804233Z 23:08:17.680 DEBUG: Parsed Visual Studio Test Counters - total: 3, failed: 0, errors: 0, timeout: 0, aborted: 0, executed: 3.
2021-08-04T23:08:17.6840310Z 23:08:17.683 INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=57ms
2021-08-04T23:08:17.6846369Z 23:08:17.684 INFO: Sensor Zero Coverage Sensor
2021-08-04T23:08:17.7097779Z 23:08:17.704 INFO: Sensor Zero Coverage Sensor (done) | time=20ms

What should I do next?

NVM I got it! the template I was using indicate $(Agent.TempDirectory) while it should be $(Agent.BuildDirectory)

1 Like

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