简体   繁体   中英

How to include xUnit tests code coverage in SonarQube?

The documentation I found was scattered and not much to the point.

So, how to include xUnit tests code coverage in SonarQube in a .NET Core project?

I was able to update code coverage in my project (.NET Core 2.2 with xUnit) through the following:

First I installed the NuGet package XunitXml.TestLogger .

Then I manually executed the following commands in order to update SonarQube's stats:

dotnet "PathTo\sonar-scanner-msbuild-4.6.2.2108-netcoreapp2.0\SonarScanner.MSBuild.dll" begin /k:"ProjectName" /d:sonar.host.url="https://sonarqube.ourserver.com.br" /d:sonar.login="token" /d:sonar.cs.xunit.reportsPaths="PathTo\TestResults.xml"

dotnet build Path\Project.sln

dotnet test --test-adapter-path:. --logger:xunit

dotnet "PathTo\sonar-scanner-msbuild-4.6.2.2108-netcoreapp2.0\SonarScanner.MSBuild.dll" end /d:sonar.login="token" 

The dotnet test line command generates the XML referenced in the first command.

References:

https://docs.sonarqube.org/latest/analysis/coverage/

https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/

https://community.sonarsource.com/t/coverage-test-data-generate-reports-for-c-vb-net/9871

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM