Generating XUnit Code Coverage Reports for SonarQube
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.
dotnet add package coverlet.collector
Setup the "test" task in the Tests project
"test", "/p:CollectCoverage=true", "/p:CoverletOutputFormat=opencover"
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.
About Sean Nelson
I like codes and stuff.