50 lines
2.1 KiB
PowerShell
50 lines
2.1 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
# Script to run tests with detailed code coverage using coverlet.msbuild
|
|
|
|
Write-Host "Running tests with detailed code coverage..." -ForegroundColor Green
|
|
|
|
# Run tests with coverlet.msbuild
|
|
dotnet test `
|
|
/p:CollectCoverage=true `
|
|
/p:CoverletOutputFormat=cobertura `
|
|
/p:CoverletOutput=./coverage/ `
|
|
/p:Exclude="[*]*.Migrations.*" `
|
|
/p:ExcludeByFile="**/Migrations/*.cs"
|
|
|
|
Write-Host "`nTest execution completed!" -ForegroundColor Green
|
|
|
|
# Find the coverage file
|
|
$coverageFile = Get-ChildItem -Path "./ChatBot.Tests/coverage" -Filter "coverage.cobertura.xml" -ErrorAction SilentlyContinue
|
|
|
|
if ($coverageFile) {
|
|
Write-Host "Coverage file location:" -ForegroundColor Cyan
|
|
Write-Host $coverageFile.FullName -ForegroundColor White
|
|
|
|
# Parse and display coverage percentage
|
|
[xml]$coverageXml = Get-Content $coverageFile.FullName
|
|
$lineRate = [double]$coverageXml.coverage.'line-rate'
|
|
$branchRate = [double]$coverageXml.coverage.'branch-rate'
|
|
$linesCovered = [int]$coverageXml.coverage.'lines-covered'
|
|
$linesValid = [int]$coverageXml.coverage.'lines-valid'
|
|
|
|
$coveragePercent = [math]::Round($lineRate * 100, 2)
|
|
$branchPercent = [math]::Round($branchRate * 100, 2)
|
|
|
|
Write-Host "`n========================================" -ForegroundColor Green
|
|
Write-Host "COVERAGE RESULTS:" -ForegroundColor Yellow
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host "Line Coverage: $coveragePercent% ($linesCovered / $linesValid)" -ForegroundColor White
|
|
Write-Host "Branch Coverage: $branchPercent%" -ForegroundColor White
|
|
Write-Host "========================================`n" -ForegroundColor Green
|
|
|
|
if ($coveragePercent -lt 70) {
|
|
Write-Host "⚠️ Coverage is below 70%" -ForegroundColor Red
|
|
} elseif ($coveragePercent -lt 80) {
|
|
Write-Host "✅ Coverage is acceptable (70-80%)" -ForegroundColor Yellow
|
|
} else {
|
|
Write-Host "🎉 Excellent coverage (80%+)" -ForegroundColor Green
|
|
}
|
|
} else {
|
|
Write-Host "Coverage file not found!" -ForegroundColor Red
|
|
}
|