SonarQube Could not import unit test report for xUnit

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    -Community Edition Version 8.5 (build 37579)
    -sonar-scanner-msbuild-5.5.3.43281-net5.0

  • what are you trying to achieve
    -trying to import test execution report into sonarqube server

  • what have you tried so far to achieve this

I have NET5 xUnit test project. On the build server in CI/CD pipeline I am generating the test coverage report and test execution report with below batch commands. I am using dotnet test to generate reports.

dotnet "C:\sonar-scanner-msbuild-5.5.3.43281-net5.0\SonarScanner.MSBuild.dll" begin /k:"IM" /d:sonar.host.url="myhost.com" /d:sonar.login="xxxxxxx" /d:sonar.cs.opencover.reportsPaths="%WORKSPACE%\Tests\**\TestResults\*\coverage.opencover.xml" /d:sonar.cs.xunit.reportsPaths="%WORKSPACE%\Tests\**\TestResults\TestOutput.xml"

dotnet build "%WORKSPACE%\IM.sln" -nr:false

dotnet test --no-build "%WORKSPACE%\Tests\MyProject1.UnitTests\MyProject.UnitTests.csproj" --logger:trx;LogFileName="%WORKSPACE%\Tests\MyProject1.UnitTests\TestResults\TestOutput.xml" --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover

dotnet "C:\sonar-scanner-msbuild-5.5.3.43281-net5.0\SonarScanner.MSBuild.dll" end /d:sonar.login="xxxxxxx"

This creates two reports
...\TestResults\2417ade5-748d-4e44-8129-faa8d64f67b5\coverage.opencover.xml
and
...\TestResults\TestOutput.xml

The scanner was able to import coverage report into SonarQube server. However scanner is not able to import test execution report. It throws warning

INFO: Sensor C# Unit Test Results Import [csharp]
INFO: Parsing the XUnit Test Results file ‘…\TestResults\TestOutput.xml’.
WARN: Could not import unit test report ‘…\TestResults\TestOutput.xml’

I verified the TestOutput.xml file exists at the given location

Hello @LP2020

Could you please check what does the TestOutput.xml file contain?
Does it contain the test results or the build logs?

All the best,
Čaba

This topic was automatically closed after 10 days. New replies are no longer allowed.