-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-coverage.ps1
More file actions
61 lines (49 loc) · 1.94 KB
/
run-coverage.ps1
File metadata and controls
61 lines (49 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# PowerShell script to generate and open HTML code coverage report
# Requires: dotnet test with coverlet.collector in test project references
# Prerequisites: Run 'dotnet tool restore' once to install ReportGenerator
Write-Host "🧹 Cleaning old coverage artifacts..." -ForegroundColor Green
# Remove old test results and coverage report
if (Test-Path "TestResults") {
Remove-Item -Recurse -Force -Path "TestResults" | Out-Null
Write-Host " ✓ Removed TestResults/" -ForegroundColor Gray
}
if (Test-Path "coverage_report") {
Remove-Item -Recurse -Force -Path "coverage_report" | Out-Null
Write-Host " ✓ Removed coverage_report/" -ForegroundColor Gray
}
Write-Host ""
Write-Host "🧪 Running tests with XPlat Code Coverage collection..." -ForegroundColor Green
Write-Host ""
# Run tests with code coverage
dotnet test `
--configuration Release `
--collect:"XPlat Code Coverage" `
--results-directory TestResults `
--logger "console;verbosity=normal"
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "❌ Tests failed or coverage collection failed." -ForegroundColor Red
exit $LASTEXITCODE
}
Write-Host ""
Write-Host "📊 Generating HTML coverage report..." -ForegroundColor Green
Write-Host ""
# Generate HTML report using ReportGenerator
dotnet tool run reportgenerator `
-reports:"TestResults/**/coverage.cobertura.xml" `
-targetdir:"coverage_report" `
-reporttypes:Html
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "❌ ReportGenerator failed." -ForegroundColor Red
exit $LASTEXITCODE
}
Write-Host ""
Write-Host "✅ Coverage report generated successfully!" -ForegroundColor Green
Write-Host ""
Write-Host "📂 Report location: coverage_report/index.html" -ForegroundColor Cyan
Write-Host "🌐 Opening in default browser..." -ForegroundColor Green
Write-Host ""
# Open the report in default browser
Start-Process "coverage_report/index.html"
Write-Host "✨ Done!" -ForegroundColor Green