Reputation: 41
I am using sonarQube to analyze my code that in .net6. I've installed sonarScanner and run these 3 commands:
dotnet sonarscanner begin /k:"<sonar-project-key>"
/d:sonar.login="<sonar-token>"
/d:sonar.cs.dotcover.reportsPaths=dotCover.Output.html
dotnet build –no-incremental
dotnet dotcover test --dcReportType=HTML
dotnet sonarscanner end /d:sonar.login="<sonar-token>"
I wrote a lot of unit tests using nunit however the number of unit tests is 0
I tried to add /d:sonar.cs.nunit.reportsPaths="Nunit\Result.xml" but nothing happened
Can you please help to reveal the missing configuration?
Upvotes: 4
Views: 1160
Reputation: 4550
In case you want to use the global tool, here are the steps
dotnet tool install --global coverlet.console
/d:sonar.cs.opencover.reportsPaths=coverage.opencover.xml /d:sonar.cs.vstest.reportsPaths=<PATH to This File>TestResult.trx
coverlet <Path to this DLL>SpeQue.Service.Test.dll --target "dotnet" --targetargs "test <Directory of the Test> --no-build --logger:\"trx;LogFileName=TestResult.trx\"" --format opencover
Note: It is vital to associate sonar.cs.vstest.reportsPaths with the trx file to show the number of unit test cases. Coverage % will be pulled from coverage.opencover.xml
Upvotes: 0
Reputation: 108
I fixed that using Coverlet and exporting to OpenCover format.
Make sure these packages are added to your xunit test project:
coverlet.collector
coverlet.msbuild
To scan:
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput="../../" --logger:"trx;LogFileName=..\..\..\TestResult.trx"
dotnet sonarscanner begin /k:"test" /d:sonar.host.url="http://localhost:9000" /d:sonar.token="XXX" /d:sonar.cs.opencover.reportsPaths="coverage.opencover.xml" /d:sonar.cs.vstest.reportsPaths=TestResult.trx
dotnet build
dotnet sonarscanner end /d:sonar.token="XXX"
Note: in this example the unit tests is located on "\tests\Project.Tests\Project.Tests.csproj", so the output will be placed on "\". This is also the path where the scanner is run.
Upvotes: 1