Xunit CodeCoverage in SonarCloud

Hi

I played around with SonarCube and used a local script which runs the sonar scanner and collect codecoverage. (See the script at the end of the post)

Now I’d like to use the gitlab and sonarcloud integration. For this i followed the generic integration guide for gitlab and added that step to my gitlab configuration.
But what is now the common strategy to create the codecoverage data ? Is there a example somewhere?

Do I have to run the unit tests in a previous step and let it them automatically collect the data?

dotnet sonarscanner begin /k:"projectkey" /d:sonar.host.url="{{mySonarServer}"  /d:sonar.login="foo"  /d:sonar.coverageReportPaths="C:\sonar\sonarqubecoverage\SonarQube.xml" /d:sonar.dotnet.excludeTestProjects=true

dotnet build myproject
dotnet test myproject  --no-build --collect:"XPlat Code Coverage"
reportgenerator "-reports:myproject\TestResults\*\coverage.cobertura.xml;

Hi @Boas_Enkler,

Welcome to our community!

You can find here a detailed guide for importing coverage data into SonarQube. Please take a look and let us know if you experience any issues.

Best,
Costin