-
Notifications
You must be signed in to change notification settings - Fork 39
C# support
Andrew Thigpen edited this page May 14, 2023
·
1 revision
See related PR
The dotnet test tool per default writes one coverage result per test project. In addition to that the output is not deterministic and contains a subfolder with GUID per test run which are not deleted when another test run is started. To tackle this a script like the following is recommended to collect all coverage results in a solution and merge it to a single results file, which then can be picked up by the coverage extension.
The ReportGenerator dotnet tool is used for merging reports
The script is written in powershell core which should work cross platform or can be easily translated to a bash script:
$projectTestResultName = "coverage.cobertura.xml"
# delete all previous test result of each test project to have correct report generator input
Get-ChildItem -include $projectTestResultName -recurse | ForEach-Object { Remove-Item $_.Directory -recurse }
# run tests
dotnet test --collect:"XPlat Code Coverage"
# merge reports
reportgenerator -reports:**/TestResults/*/$projectTestResultName -reporttypes:lcov -targetdir:TestResults