Search code examples
c#msbuildsonarqubexunitsonar-runner

Test success rate not showing in sonar unit test widget for dotnet project


I have ran sonar runner for msbuild on a c# dot net project. After running below is the result I got in unit test widget,

overall unit test result

It doesn't show unit test success rate. While further checking I found that unit test for each file also not showing as below.

unit test result for each file I have followed Unit Test Execution Results Import (C#, VB.NET) documentation page while doing this. I have executed below shell commands to run sonar runner

SET dotnet="C:\Program Files\dotnet\dotnet.exe"
SET opencover=C:\Users\lakshmanu\.nuget\packages\opencover\4.6.519\tools\OpenCover.Console.exe 
SET targetargs="test -f netcoreapp2.0 -c Release test/Services/UnitTest/UnitTest.csproj"  
SET filter="+[Test.MyTest.*]* -[*.Test]* -[xunit.*]* -[another]*"  
SET coveragefile=Coverage.xml

dotnet restore %WORKSPACE%\Myproj\My.API

MSBuild.SonarQube.Runner.exe begin /k:"test" /n:"test" /v:"1" /s:%WORKSPACE%\SonarQube.Analysis.xml /d:sonar.cs.opencover.reportsPaths="Coverage.xml" /d:sonar.cs.xunit.reportsPaths="D:\sources\test\Services\UnitTest\XUnitResults.xml"

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" Myproj.sln /t:Rebuild

REM Run code coverage analysis  
%opencover% -oldStyle -register:user -target:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" -targetargs:"test\Services\UnitTest\bin\Debug\netcoreapp2.0\UnitTest.dll /Framework:FrameworkCore10" -filter:%filter% -output:%coveragefile% -skipautoprops -hideskipped:All
cd test\Services\UnitTest\
dotnet xunit -xml XUnitResults.xml
cd ..\..\..

MSBuild.SonarQube.Runner.exe end

Tests are written using xunit framework. Sonarqube version is 5.6.6. Any clue on why test success rate or unit test per file is not showing?

UPDATE

While googling I found this question, according to that and sonarqube documentation number of unit test per each file is not supported at the moment.


Solution

  • SonarQube simply doesn't track those metrics.

    Theoretically, your unit test success rate should always be 100%. Anything less should fail the build and preempt the analysis.