Tags
By default running dotnet test doesn't save the test results to a file. To generate a report in a format you can provide to SonarQube follow the steps below.
Install Coverlet
dotnet add package coverlet.collector
Setup the "test" task in the Tests project
{
"label": "test",
"command": "dotnet",
"args": [
"test", "/p:CollectCoverage=true", "/p:CoverletOutputFormat=opencover"
],
"problemMatcher": "$msCompile"
}
Now running dotnet test will also save the output to a file named "coverage.opencover.xml", which can be added to the project in SonarQube by going to Project > Administration > General Settings > C# and adding the path to the report in the "OpenCover Unit Tests Reports Paths"..
Instead of providing the report path via the SonarQube web administration gui, the following parameter can be supplied to the dotnet sonarscanner begin command.
/d:sonar.cs.opencover.reportsPaths=coverage.opencover.xml
About Sean Nelson
I like codes and stuff.
|
735 comments