SonarQube code coverage with dotnet 10 sdk and Testing Platform

Summary

The issue at hand is the inability to upload a code coverage report to SonarQube analyses in an Azure pipeline for a .NET 10 application using the .NET 10 SDK. The application uses the Microsoft Testing Platform (MTP) for tests and coverage. Key challenges include:

  • Understanding the correct format for code coverage reports that SonarQube supports
  • Configuring the Azure pipeline to generate and upload the correct report format

Root Cause

The root cause of the issue is the mismatch between the code coverage report format generated by the dotnet test command and the format expected by SonarQube. The --coverage-output-format xml option generates a report in a format that is not directly supported by SonarQube. Specific causes include:

  • The dotnet test command generates a report in a format that is not compatible with SonarQube
  • The OpenCover report type does not generate a report that can be used by SonarQube
  • The Cobertura format is not supported by SonarQube

Why This Happens in Real Systems

This issue occurs in real systems due to incompatible report formats and misconfiguration of the Azure pipeline. Common reasons include:

  • Lack of understanding of the supported report formats by SonarQube
  • Incorrect configuration of the dotnet test command and the Azure pipeline tasks
  • Insufficient documentation and guidance on configuring code coverage reports for SonarQube

Real-World Impact

The real-world impact of this issue is the inability to track code coverage and quality metrics in SonarQube, leading to poor code quality and increased technical debt. Specific impacts include:

  • Inability to track code coverage and quality metrics
  • Poor code quality and increased technical debt
  • Difficulty in identifying areas of the code that need improvement

Example or Code

dotnet test -c Release --solution solution.slnx --report-trx --coverage --coverage-output-format xml

This command generates a code coverage report in a format that is not directly supported by SonarQube.

How Senior Engineers Fix It

Senior engineers fix this issue by configuring the Azure pipeline to generate a report in a format supported by SonarQube, such as vscoveragexml. Steps to fix include:

  • Using the dotnet-coverage tool to merge coverage files into a single XML report
  • Configuring the Azure pipeline to generate a report in the vscoveragexml format
  • Updating the SonarQube prepare task to point to the correct report path

Why Juniors Miss It

Juniors may miss this issue due to lack of experience with configuring code coverage reports and insufficient understanding of the supported report formats by SonarQube. Common mistakes include:

  • Not understanding the correct format for code coverage reports
  • Not configuring the Azure pipeline correctly to generate and upload the report
  • Not testing the report upload to ensure it is working correctly