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)

  • 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-\SonarScanner.MSBuild.dll" begin /k:"IM" /"" /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-\SonarScanner.MSBuild.dll" end /d:sonar.login="xxxxxxx"

This creates two reports

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,

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