Sonar scanner code coverage using xunit InlineData xml file input and output

Hello
I develop library in c# 4.7.2

I develop libray of unit tests using xunit 2.9.0

In my pipeline I have a step to run sonar

All working fine, but when I look at the codecoverage, the value is 0%

I don’t understand why

The environment is

  • SonarQube server 9.9.1.69595
  • SonarScanner 4.8.0.2856
  • SonarScanner for MSBuild 5.11
  • jdk-19.0.1
  • Windows Server 2019
  • Project c# 4.7.2
  • xunit 2.9.0
  • Pipeline jenkins with jenkinsfile
  • dotnet-coverage collect

The goal of the library is transformed an xml received in input and generated a new xml file in output

Then the unit test used InlineData with xml input and xml output, and compare the xml generated with the xml declared as InlineData

The tests are running successfully, but the code coverage is not computed

I don’t know what is missing

The jenkins file contains a step

withSonarQubeEnv(‘Myenv-SonarQube’) {
bat label: ‘Starting Sonar analysis’, script: ‘dotnet ’ + sqScannerMsBuildHome + ’ begin /k:’ + MY_PROJECT_NAME + ’ /n:’ + MY_PROJECT_NAME + ’ ’ + ‘/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.qualitygate.wait=true ’ + ’ /v:’ + env.GitVersion_NuGetVersion + ‘_(#’ + env.BUILD_NUMBER + ‘)’ + ’ /d:sonar.dotnet.excludeTestProjects=true ’
bat label: ‘Building application with dotnet’, script: ‘“C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe” /t:restore,build MyPlugInTest\MyPlugInTest.csproj /p:Configuration=Debug /p:OutputPath=Publish\MySuffix’ + env.GitVersion_NuGetVersion + ’ /p:TargetFrameworkVersion=v4.7.2’
bat label: ‘Testing and coverage’, script: ‘dotnet-coverage collect "dotnet test “’ + projectDll + ‘” --filter DisplayName=MyPlugInTest.MyClassTest.Should_Succeed " -f xml -o “coverage.xml”’
bat label: ‘Ending Sonar analysis’, script: 'dotnet ’ + sqScannerMsBuildHome + ’ end ’
}

Thanks for your help and suggestion

Hi,

Welcome to the community!

Your version is past EOL. You should update to either the latest version or the current LTA (long-term active version) at your earliest convenience. Your update path is:

9.9.1 → 2025.1.4 → 2026.1

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

If your error persists after update, please come back to us.

 
Ann