- ALM used : Azure DevOps
- CI system used : Azure DevOps
- Scanner command used :
- task: SonarCloudPrepare@1
inputs:
SonarCloud: '[name of the service connection'
organization: '[name of our organization]'
scannerMode: 'MSBuild'
projectKey: '[project key for our project]'
projectName: '[name of our project]'
extraProperties: |
sonar.cs.vstest.reportsPaths=$(TestOutputDirectory)/*.trx
sonar.coverageReportPaths=$(TestOutputDirectory)/mergedcoveragereport/SonarQube.xml
sonar.coverage.exclusions=**/*Tests*/**/*
sonar.inclusions=**/*.cs
- task: DotNetCoreCLI@2
displayName: 'NuGet Restore'
inputs:
command: 'restore'
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
- task: DotNetCoreCLI@2
displayName: 'Build solution'
inputs:
command: 'build'
- task: DotNetCoreCLI@2
displayName: 'Test solution'
continueOnError: true
inputs:
command: 'test'
projects: '**/*Tests.csproj'
arguments: '--logger trx --collect:"XPlat Code Coverage" --results-directory $(TestOutputDirectory)'
publishTestResults: false
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '*.trx'
searchFolder: '$(TestOutputDirectory)'
failTaskOnFailedTests: true
- task: reportgenerator@5
inputs:
reports: '$(TestOutputDirectory)/*/coverage.cobertura.xml'
targetdir: '$(TestOutputDirectory)/mergedcoveragereport'
reporttypes: 'Cobertura;SonarQube'
assemblyfilters: '-*Tests*'
- task: PublishCodeCoverageResults@1
displayName: 'Publish CodeCoverage Results'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(TestOutputDirectory)/mergedcoveragereport/Cobertura.xml'
failIfCoverageEmpty: true
- task: SonarCloudAnalyze@1
displayName: 'SonarCloud Analyze'
- task: SonarCloudPublish@1
displayName: 'SonarCloud Publish'
inputs:
pollingTimeoutSec: '300'
-
Languages of the repository : C#
-
Error observed: SonarCloud incorrectly showing 0% code coverage, although 155 out of 202 lines are actually covered according to SonarCloud:
SonarCloud Analysis log.txt (4.9 KB)
Cobertura.txt (28.3 KB)
What can we do to fix the 0% code coverage being shown?