I am getting 0% Coverage on my Project

Template for a good new topic, formatted with Markdown:

  • ALM used - Azure DevOps
  • CI system used - Azure DevOps
  • Scanner command used when applicable -
      inputs:
        SonarQube: 'sonarqube-integration'
        scannerMode: 'MSBuild'
        projectKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
        projectName: 'Rulebot_ICRuleEngine'
        extraProperties: |
          # Additional properties that will be passed to the scanner, 
          # Put one key=value per line, example:
          # sonar.exclusions=**\*.bin          sonar.cobertura.reportPaths=$(Agent.TempDirectory)/coverage_reports/coverage.cobertura.xml
          sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/coverage_reports/coverage.opencover.xml
          sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/**/*.trx```
  • Languages of the repository - .Net
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
  • Steps to reproduce
  1. Added the sonarqube tasks to the pipeline.
  2. Coverage report is being generated on the unit test.
      displayName: 'dotnet test'
      condition: eq(variables.buildSuccess, 'true')
      inputs:
        command: 'test'
        projects: 'ICRuleEngine/TestProject/TestProject.csproj'
        arguments: '--collect:"XPlat Code Coverage" --diag:$(System.DefaultWorkingDirectory)\folder\log.txt --logger trx -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover,cobertura'
        publishTestResults: true
  1. The coverage published on the pipeline is showing 34% but the coverage in sonarqube is 0%
  • Potential workaround

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hi,

Welcome to the community!

Can you share verbose logs, please?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@3
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'dotnet'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

 
Thx,
Ann