.net codecoverage not uploaded to SonarQube

I have a Azure DevOps pipeline that runs some unit tests on a .NET 6 code base.
In the DevOps pipeline the results of the unit tests are shown and I also see a coverage report in DevOps.
Issues in code are properly reported to SonarQube.
But the coverage result from the unit test does not show up in SonarQube.

My build pipeline is configured as follows:

trigger:
  branches: 
    include:
      - main
  paths:
    exclude:
      - terraform/**
      - FlexGateway/**
      - k8s_gitops/**

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: 'zib-intben-dev-ibapisacrdev'
  imageRepository: 'ibxxxxeactivities'
  containerRegistry: 'ibapisacrdev.azurecr.io'
  dockerfilePath: 'dockerfile'
  tag: '$(Build.BuildId)'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: Build
  displayName: Build and push stage
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: SonarQubePrepare@5
      inputs:
        SonarQube: 'SonarQubeLoyaltyAPI'
        scannerMode: 'MSBuild'
        projectKey: 'XXXXXXX'
        projectName: 'XYZ'
        xtraProperties: |
          sonar.branch.name=$(Build.SourceBranchName)

    - task: DotNetCoreCLI@1
      displayName: Run unit tests
      inputs:
        command: test
        projects: '**/*_Test/*.csproj'
        arguments: '--configuration debug -l:trx;LogFileName=TestOutput.xml --collect:"XPlat Code Coverage"'
        publishTestResults: true
    - task: PublishTestResults@2
      inputs:
        testResultsFormat: 'VSTest' # 'JUnit' | 'NUnit' | 'VSTest' | 'XUnit' | 'CTest'. Alias: testRunner. Required. Test result format. Default: JUnit.
        testResultsFiles: '**/TestOutput.xml' # string. Required. Test results files. Default: **/TEST-*.xml.
    - task: PublishCodeCoverageResults@2
      inputs:
        summaryFileLocation: '**/coverage.cobertura.xml'
    - task: DotNetCoreCLI@2
      displayName: .NET Publish project
      inputs:
        command: 'publish'
        arguments: '-c Release -o $(Build.ArtifactStagingDirectory)'
        publishWebProjects: false
        projects: 'IB_XXXX_Activities/IB_XXXX_Activities.csproj'
    - task: SonarQubeAnalyze@5
      inputs:
        jdkversion: 'JAVA_HOME_11_X64'
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)/IB_XXXX_Activities.zip'
        ArtifactName: 'IB_XXXX_Activities'
        publishLocation: 'Container'
    - task: SonarQubePublish@5
      inputs:
        pollingTimeoutSec: '300'

Hi,

Welcome to the community!

It’s not clear to me what your coverage engine is. Visual Studio? If so, there’s no need for that coverage.cobertura.xml file. The docs should help.

 
Ann

I use the dotnet tool chain and followed the section visual-studio-code-coverage.

This step in the build pipeline is to upload the coverage information into the AzureDevOps job:

    - task: PublishCodeCoverageResults@2
      inputs:
        summaryFileLocation: '**/coverage.cobertura.xml'

This works fine → I can see coverage information in DevOps.

But coverage of unit tests is not showing in SonarQube.
Not sure what I miss as the documentation says “No further configuration is required”.

Hi,

Okay, then we’ll need some more information. Please give us the following:

  • what is the version of SonarQube that you are using?
  • what is the version of the Scanner for .NET (MSBuild) that you are using?
  • what version of MSBuild are you using?

And we’ll need the logs:

  • please give us the verbose output of the scanner commands (please run SonarScanner.MSBuild.exe begin /k:“MyProject” /d:sonar.verbose=true as the begin step, and please attach the output of the BEGIN and END steps)
  • please give the output of running MSBuild in verbose mode (/v:d)

In addition, please see the following guides:

 
Ann

Hi

According to the logs I’m using the following versions:
SonarQube: 5.18.4
SonarScanner for MSBuild: 5.15
MSBuild: Not sure which version is used hare.

The Azure DevOps pipeline is setup following this instructions:
.NET test coverage (sonarsource.com)

I can’t share the logs in a public forum.
Is it possible to send them directly to you?

Hi,

Can you check your SonarQube page footer to get the version, please?

 
Thx,
Ann

Enterprise Edition Version 9.9.1 (build 69595)

Hi,

Thanks for the version. Feel free to redact your logs as necessary.

 
Thx,
Ann

Ok, attached the logs.
DevOpsLog.txt (102.8 KB)

Hi,

Thanks for the log. I see no attempt in it to process your .NET coverage.

You say you followed the docs, but in revisiting your pipeline, I’m not seeing the --collect "Code Coverage" part of the dotnet test` command.

Can you add that and retry?

 
Ann

Here you give the following instructions:

I have exactly this in my pipeline:
image

In the logs you see the following:

But still I don’t get code coverage in SonarQube.

Hi,

That’s not what I’m seeing in the pipeline code you published earlier:

 
Ann

Yes that is correct.
I adjusted this part to be 100% in line with the config you suggest this morning.
Unfortunately this did not solve the issue → coverage is still not showing up in SonarQube.

Hi,

Can we have the new log, then?

 
Thx,
Ann

Hi Ann

New log is attached.

Regards,

Simon
DevOpsLogsV2.txt (97.7 KB)

Hi,

Thanks for the log. I’m not seeing anything related to the coverage report being picked up in it (just like the previous one).

Can you provide a debug log for the end step, please?

 
Thx,
Ann

attached the logs.
DevOpsLogsV3.txt (441.6 KB)

Hi,

Thanks for the debug log. Finally, we have something relevant. A whole bunch of lines line this:

'VisualStudioCoverage' skipped because there is no related file in current project

I’m guessing that if you went back to the debug begin step log, you would see each of your projects in turn being classified as test projects. This should help sort that out.

 
Ann

The following was missing in *.csproj file:

    </ItemGroup>

    <ItemGroup>
        <ProjectCapability Include="TestContainer" />
    </ItemGroup>
    
</Project>

Now I see the following in the begin part (this was not in previously:

2023-12-05T06:27:03.3066876Z 20BE94BB-0449-447F-BB45-1F5A437AFBE0.sonar.working.directory=/home/vsts/work/1/.sonarqube/out/.sonar/mod5
2023-12-05T06:27:03.3068351Z 62B8FDAF-B815-4B0C-ADE3-1E2E49F5DF5F.sonar.projectKey=GT50-LAPI-921298bb-0cec-4e68-8e49-01a1facd6881:62B8FDAF-B815-4B0C-ADE3-1E2E49F5DF5F
2023-12-05T06:27:03.3069716Z 62B8FDAF-B815-4B0C-ADE3-1E2E49F5DF5F.sonar.projectName=XXXXX_Activities_Test
2023-12-05T06:27:03.3070912Z 62B8FDAF-B815-4B0C-ADE3-1E2E49F5DF5F.sonar.projectBaseDir=/home/vsts/work/1/s/XXXXX_Activities_Test
2023-12-05T06:27:03.3071975Z 62B8FDAF-B815-4B0C-ADE3-1E2E49F5DF5F.sonar.sourceEncoding=utf-8
2023-12-05T06:27:03.3072551Z 62B8FDAF-B815-4B0C-ADE3-1E2E49F5DF5F.sonar.sources=
2023-12-05T06:27:03.3073049Z 62B8FDAF-B815-4B0C-ADE3-1E2E49F5DF5F.sonar.tests=\
2023-12-05T06:27:03.3073657Z "/home/vsts/work/1/s/XXXXX_Activities_Test/AchievementsUnitTest.cs",\
2023-12-05T06:27:03.3074467Z "/home/vsts/work/1/s/XXXXX_Activities_Test/ActivityImplUnitTest.cs",\
2023-12-05T06:27:03.3075233Z "/home/vsts/work/1/s/XXXXX_Activities_Test/DBBasedTest.cs",\
2023-12-05T06:27:03.3076093Z "/home/vsts/work/1/s/XXXXX_Activities_Test/EmployeesControllerAchievementsUnitTest.cs",\
2023-12-05T06:27:03.3077119Z "/home/vsts/work/1/s/XXXXX_Activities_Test/EmployeesControllerActivitiesUnitTest.cs",\
2023-12-05T06:27:03.3078240Z "/home/vsts/work/1/s/XXXXX_Activities_Test/EmployeesControllerActivityTemplatesUnitTest.cs",\
2023-12-05T06:27:03.3079275Z "/home/vsts/work/1/s/XXXXX_Activities_Test/GetActivityTemplatesFromDbUnitTest.cs",\
2023-12-05T06:27:03.3080209Z "/home/vsts/work/1/s/XXXXX_Activities_Test/LiveWellActivityImplUnitTest.cs",\
2023-12-05T06:27:03.3081063Z "/home/vsts/work/1/s/XXXXX_Activities_Test/LiveWellPointsUnitTest.cs",\
2023-12-05T06:27:03.3081849Z "/home/vsts/work/1/s/XXXXX_Activities_Test/PointsUnitTest.cs",\
2023-12-05T06:27:03.3082608Z "/home/vsts/work/1/s/XXXXX_Activities_Test/RecomondationsUnitTest.cs",\
2023-12-05T06:27:03.3083478Z "/home/vsts/work/1/s/XXXXX_Activities_Test/TrainingDataControllerUnitTest.cs",\
2023-12-05T06:27:03.3084259Z "/home/vsts/work/1/s/XXXXX_Activities_Test/Usings.cs"

Unfortunately I still do not see coverage info in SonarQube :frowning:

In the logs it still says it skiped converage:

2023-12-05T06:32:06.3164889Z 06:32:06.316 INFO: ------------- Run sensors on module XXXXX_Activities_Test
2023-12-05T06:32:06.3181049Z 06:32:06.317 INFO: Configuring Mule Plugin...
2023-12-05T06:32:06.5772884Z 06:32:06.574 DEBUG: 'JavaSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5782592Z 06:32:06.574 DEBUG: 'CobolSquidSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5784026Z 06:32:06.574 DEBUG: 'Import external issues report' skipped because one of the required properties is missing
2023-12-05T06:32:06.5785809Z 06:32:06.574 DEBUG: 'Import external issues report from SARIF file.' skipped because one of the required properties is missing
2023-12-05T06:32:06.5787139Z 06:32:06.574 INFO: [mule4] Checking if mule4 coverage sensor is applicable for current language...
2023-12-05T06:32:06.5788925Z 06:32:06.574 DEBUG: 'com.zurich.c4e.sonarqube.mule.extensions.MuleCoverageSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5790379Z 06:32:06.574 DEBUG: 'PmdSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5791822Z 06:32:06.574 DEBUG: 'IaC Terraform Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5793560Z 06:32:06.574 DEBUG: 'IaC CloudFormation Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5795073Z 06:32:06.574 DEBUG: 'IaC Kubernetes Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5796679Z 06:32:06.574 DEBUG: 'PL/SQL Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5798174Z 06:32:06.574 DEBUG: 'Scala Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5800158Z 06:32:06.575 DEBUG: 'Scoverage sensor for Scala coverage' skipped because there is no related file in current project
2023-12-05T06:32:06.5802404Z 06:32:06.575 DEBUG: 'Import of Scalastyle issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5803639Z 06:32:06.575 DEBUG: 'Import of Scapegoat issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5804895Z 06:32:06.575 DEBUG: 'Import of Checkstyle issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5805974Z 06:32:06.575 DEBUG: 'Import of PMD issues' skipped because one of the required properties is missing
2023-12-05T06:32:06.5807049Z 06:32:06.575 DEBUG: 'Import of SpotBugs issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5808096Z 06:32:06.575 DEBUG: 'SurefireSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5809156Z 06:32:06.575 DEBUG: 'Removed properties sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5810134Z 06:32:06.575 DEBUG: 'HTML' skipped because there is no related file in current project
2023-12-05T06:32:06.5810996Z 06:32:06.575 DEBUG: 'Flex' skipped because there is no related file in current project
2023-12-05T06:32:06.5811924Z 06:32:06.575 DEBUG: 'Flex Cobertura' skipped because there is no related file in current project
2023-12-05T06:32:06.5812867Z 06:32:06.575 DEBUG: 'XML Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5813850Z 06:32:06.575 DEBUG: 'CheckstyleSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5814953Z 06:32:06.575 DEBUG: 'Swift Code Quality and Security' skipped because there is no related file in current project
2023-12-05T06:32:06.5816291Z 06:32:06.575 DEBUG: 'Import of SwiftLint issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5817292Z 06:32:06.575 DEBUG: 'gcov' skipped because there is no related file in current project
2023-12-05T06:32:06.5818182Z 06:32:06.575 DEBUG: 'llvm-cov' skipped because there is no related file in current project
2023-12-05T06:32:06.5819090Z 06:32:06.575 DEBUG: 'cppunit' skipped because there is no related file in current project
2023-12-05T06:32:06.5820063Z 06:32:06.575 DEBUG: 'VisualStudioCoverage' skipped because there is no related file in current project
2023-12-05T06:32:06.5821053Z 06:32:06.575 DEBUG: 'bullseye' skipped because there is no related file in current project
2023-12-05T06:32:06.5822002Z 06:32:06.575 DEBUG: 'Python Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5823127Z 06:32:06.575 DEBUG: 'Cobertura Sensor for Python coverage' skipped because there is no related file in current project
2023-12-05T06:32:06.5824268Z 06:32:06.575 DEBUG: 'PythonXUnitSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5825328Z 06:32:06.575 DEBUG: 'Import of Pylint issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5826413Z 06:32:06.575 DEBUG: 'Import of Bandit issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5827503Z 06:32:06.575 DEBUG: 'Import of Flake8 issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5834366Z 06:32:06.577 DEBUG: 'Code Quality and Security for Go' skipped because there is no related file in current project
2023-12-05T06:32:06.5835530Z 06:32:06.577 DEBUG: 'Go Unit Test Report' skipped because there is no related file in current project
2023-12-05T06:32:06.5836825Z 06:32:06.577 DEBUG: 'Go Cover sensor for Go coverage' skipped because one of the required properties is missing
2023-12-05T06:32:06.5837934Z 06:32:06.577 DEBUG: 'Import of go vet issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5839027Z 06:32:06.577 DEBUG: 'Import of Golint issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5840157Z 06:32:06.577 DEBUG: 'Import of GoMetaLinter issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5841329Z 06:32:06.577 DEBUG: 'Import of GolangCI-Lint issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5842402Z 06:32:06.577 DEBUG: 'Kotlin Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5843416Z 06:32:06.577 DEBUG: 'KotlinSurefireSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5844579Z 06:32:06.577 DEBUG: 'Import of detekt issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5845693Z 06:32:06.577 DEBUG: 'Import of Android Lint issues' skipped because one of the required properties is missing
2023-12-05T06:32:06.5846793Z 06:32:06.577 DEBUG: 'Import of ktlint issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5847802Z 06:32:06.578 DEBUG: 'RPG sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5848765Z 06:32:06.578 DEBUG: 'PliSquidSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5849740Z 06:32:06.578 DEBUG: 'T-SQL Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5850707Z 06:32:06.578 DEBUG: 'VbSquidSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5851668Z 06:32:06.578 DEBUG: 'Apex Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5852735Z 06:32:06.578 DEBUG: 'Test coverage Sensor for Apex' skipped because there is no related file in current project
2023-12-05T06:32:06.5853834Z 06:32:06.578 DEBUG: 'Import of PMD issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5854889Z 06:32:06.578 DEBUG: 'JavaScript analysis' skipped because there is no related file in current project
2023-12-05T06:32:06.5856070Z 06:32:06.578 DEBUG: 'TypeScript analysis' skipped because there is no related file in current project
2023-12-05T06:32:06.5857204Z 06:32:06.578 DEBUG: 'JavaScript inside YAML analysis' skipped because there is no related file in current project
2023-12-05T06:32:06.5858403Z 06:32:06.578 DEBUG: 'JavaScript/TypeScript Coverage' skipped because there is no related file in current project
2023-12-05T06:32:06.5859524Z 06:32:06.578 DEBUG: 'Import of ESLint issues' skipped because one of the required properties is missing
2023-12-05T06:32:06.5860585Z 06:32:06.578 DEBUG: 'Import of TSLint issues' skipped because one of the required properties is missing
2023-12-05T06:32:06.5861585Z 06:32:06.578 DEBUG: 'CSS Metrics' skipped because there is no related file in current project
2023-12-05T06:32:06.5862618Z 06:32:06.578 DEBUG: 'Import of stylelint issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5863651Z 06:32:06.578 DEBUG: 'Ruby Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5864686Z 06:32:06.578 DEBUG: 'Import of RuboCop issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5865862Z 06:32:06.578 DEBUG: 'SimpleCov Sensor for Ruby coverage' skipped because there is no related file in current project
2023-12-05T06:32:06.5866971Z 06:32:06.578 DEBUG: 'FindBugs Sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5867939Z 06:32:06.578 DEBUG: 'Dart sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5868941Z 06:32:06.578 DEBUG: 'dartanalyzer sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5870058Z 06:32:06.578 DEBUG: 'Flutter unit tests' skipped because there is no related file in current project
2023-12-05T06:32:06.5871061Z 06:32:06.578 DEBUG: 'Flutter Coverage' skipped because there is no related file in current project
2023-12-05T06:32:06.5872123Z 06:32:06.578 DEBUG: 'LintR Sensor for R files' skipped because there is no related file in current project
2023-12-05T06:32:06.5873149Z 06:32:06.578 DEBUG: 'GroovySensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5874083Z 06:32:06.578 DEBUG: 'CodeNarc' skipped because there is no related file in current project
2023-12-05T06:32:06.5875077Z 06:32:06.578 DEBUG: 'GroovySurefireSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5876150Z 06:32:06.578 DEBUG: 'Groovy CoberturaSensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5877297Z 06:32:06.578 DEBUG: 'Groovy JaCoCo Coverage' skipped because there is no related file in current project
2023-12-05T06:32:06.5878442Z 06:32:06.578 DEBUG: 'Python HTML templates processing' skipped because there is no related file in current project
2023-12-05T06:32:06.5879489Z 06:32:06.578 DEBUG: 'PHP sensor' skipped because there is no related file in current project
2023-12-05T06:32:06.5880537Z 06:32:06.578 DEBUG: 'Analyzer for "php.ini" files' skipped because there is no related file in current project
2023-12-05T06:32:06.5881659Z 06:32:06.578 DEBUG: 'Import of PHPStan issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5882754Z 06:32:06.578 DEBUG: 'Import of Psalm issues' skipped because there is no related file in current project
2023-12-05T06:32:06.5883816Z 06:32:06.578 DEBUG: 'Executes gwb inspect' skipped because there is no related file in current project
2023-12-05T06:32:06.5884851Z 06:32:06.578 DEBUG: 'AbapSquidSensor' skipped because there is no related file in current project

Attached the full logs.
DevOpsLogsV4.txt (435.8 KB)

Hi,

Could you try explicitly setting the project type?

 
Thx,
Ann