-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecCodeCoverage.ps1
More file actions
40 lines (29 loc) · 1.57 KB
/
Copy pathExecCodeCoverage.ps1
File metadata and controls
40 lines (29 loc) · 1.57 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
$TestConfig = "Debug"
$ReportFolder = './CoverageReport'
$HistoryFolder = './CoverageHistory'
$DefaultErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'silentlyContinue'
# This only needs to be installed once (globally), if installed it fails silently:
dotnet tool install -g dotnet-reportgenerator-globaltool
$ErrorActionPreference = $DefaultErrorActionPreference
# Delete previous test run results (there's a bunch of subfolders named with guids)
Get-ChildItem -include TestResults -recurse | foreach ($_) { remove-item $_.fullname -force -recurse }
# Run the Coverlet.Collector
dotnet test --collect:"XPlat Code Coverage" 2>&1 --configuration $TestConfig
# To keep a history of the Code Coverage we need to use the argument: -historydir:SOME_DIRECTORY
if (!(Test-Path $HistoryFolder)) {
New-Item -ItemType directory -Path $HistoryFolder
}
# Delete previous test run reports - note if you're getting wrong results do a Solution Clean and Rebuild to remove stale DLLs in the bin folder
if (Test-Path $ReportFolder) {
Remove-Item -Recurse -Force $ReportFolder
}
# Generate the Code Coverage HTML Report
reportgenerator -reports:"./**/coverage.cobertura.xml" -targetdir:$ReportFolder -reporttypes:Html -historydir:$HistoryFolder
# Delete test run results after use
Get-ChildItem -include TestResults -recurse | foreach ($_) { remove-item $_.fullname -force -recurse }
# Open the Code Coverage HTML Report (if running on a WorkStation)
$osInfo = Get-CimInstance -ClassName Win32_OperatingSystem
if ($osInfo.ProductType -eq 1) {
(& "$ReportFolder/index.html")
}