Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$testResultsFolder = 'TestsCodeCoverage'
$codeCoverageExecutable = '~\.nuget\packages\microsoft.codecoverage\16.6.1\build\netstandard1.0\CodeCoverage\CodeCoverage.exe'
$reportGeneratorDll = '~\.nuget\packages\reportgenerator\4.5.8\tools\netcoreapp3.0\ReportGenerator.dll'
Remove-Item $testResultsFolder -Recurse
dotnet test . --results-directory:$testResultsFolder'\CodeCoverage' --collect:"Code Coverage"
Write-Host 'Code Coverage tests completed' -ForegroundColor Green
$recentCoverageFile = Get-ChildItem -File -Filter *.coverage -Path $testResultsFolder'\CodeCoverage' -Name -Recurse | Select-Object -First 1;
&$codeCoverageExecutable analyze /output:$testResultsFolder'\LatestTestReport'.xml $testResultsFolder'\CodeCoverage\'$recentCoverageFile
Write-Host 'LatestTestReport XML generated' -ForegroundColor Green
dotnet $reportGeneratorDll "-reports:$testResultsFolder\LatestTestReport.xml" "-targetdir:$testResultsFolder\Report"
Start-Process "$testResultsFolder\Report\index.htm"
Write-Host 'LatestTestReport published and opened' -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment