Could not import xunit test report

Using SonarQube 7.9.1 and SonarScanner for MSBuild 4.7.1

J:\wks\4c69ee78>C:\jenkins-slave-build\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MSBuild-SonarScanner-default\SonarScanner.MSBuild.exe begin /**** /d:sonar.login=****** /k:oap-back /n:oap-back /v:0.0.0-unstable00001872 /d:sonar.inclusions=**/*.cs /d:sonar.cs.opencover.reportsPaths="reports\opencover.xml" /d:sonar.cs.xunit.reportsPaths="reports\nunit.xml"  
11:57:18  SonarScanner for MSBuild 4.7.1
11:57:18  Using the .NET Framework version of the Scanner for MSBuild
J:\wks\4c69ee78>C:\jenkins-slave-build\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MSBuild-SonarScanner-default\SonarScanner.MSBuild.exe end /d:sonar.login=****** 
INFO: Sensor C# Tests Coverage Report Import [csharp]
INFO: Parsing the OpenCover report J:\wks\4c69ee78\.\reports\opencover.xml
INFO: Adding this code coverage report to the cache for later reuse: J:\wks\4c69ee78\.\reports\opencover.xml
INFO: Coverage Report Statistics: 276 files, 276 main files, 276 main files with coverage, 0 test files, 0 project excluded files, 0 other language files.
INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=7737ms
INFO: Sensor C# Unit Test Results Import [csharp]
INFO: Parsing the XUnit Test Results file J:\wks\4c69ee78\.\reports\nunit.xml
WARN: Could not import unit test report '.\reports\nunit.xml'
INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=7ms

The coverage report is properly attached to the SQ analysis but not the unit test report, SQ project page shows 0 unit tests.
Is there a way to get more info about what’s the issue with the unit test report? The file exists. Is its format not the expected one? (nunit-version=“”)

hi @emex

I am a little bit confused - are you using NUnit or Xunit?

INFO: Parsing the XUnit Test Results file J:\wks\4c69ee78\.\reports\nunit.xml

You need to set different settings depending on what UT tool you are using - see [Coverage & Test Data] Generate Reports for C#,

Hi @Andrei_Epure

Here’s the command line used to run xunit and generate the coverage report with opencover:

J:\wks\dae63c14>C:\ci-tools\opencover\OpenCover.Console.exe -target:"J:\wks\dae63c14\packages\xunit.runner.console.2.2.0\tools\xunit.console.x86.exe" -output:"reports\opencover.xml" -filter:"+[*]* -[*.Test]* -[*.Tests]* -[*]*.Test -[*]*.Tests -[*]*.Test.* -[*]*.Tests.* -[xunit*]* -[Microsoft*]*" -register:user -targetargs:"J:\wks\dae63c14\src\Feature\HrefLang\tests\bin\Release\Feature.HrefLang.Test.dll dll2 etc  -maxthreads 2 -nunit reports\nunit.xml -noshadow" 

So xunit is used but with -nunit parameter. This was chosen because the report is then integrated in jenkins using the nunit plugin.
But the xunit runner can also generate the report in xunit format, see bottom of

I tried to use sonar.cs.xunit.reportsPaths and sonar.cs.nunit.reportsPaths in sonar scanner and both failed to load the report.

Hi @emex,

FYI if you are exporting the results in NUnit format then you would need to set the sonar.cs.nunit.reportsPaths property.

Does SonarQube show the source code for the test files (which I guess are in Feature.HrefLang.Test.dll)?

Can you confirm that the nunit.xml file contains the expected output i.e. that it contains the expected list of tests, and could you share the file with us?

Hi @duncanp

I switched the xunit report to ‘xml’ format (which xunit .net v2), used xunit jenkins plugin and sonar.cs.xunit.reportsPaths parameter in sonar scanner. Everything works fine with this setup.