-
Notifications
You must be signed in to change notification settings - Fork 0
/
Run-Tests.ps1
54 lines (46 loc) · 1.9 KB
/
Run-Tests.ps1
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
[CmdletBinding()]
param (
[Parameter()]
[ValidateSet('All', 'Installation', 'ActiveHours', 'Uninstallation')]
[string]$TestType = 'All'
)
# Ensure Pester is installed
if (-not (Get-Module -ListAvailable -Name Pester)) {
Write-Host "Pester not found. Installing Pester..." -ForegroundColor Yellow
Install-Module -Name Pester -Force -SkipPublisherCheck
}
Write-Host "Starting test run..." -ForegroundColor Cyan
Write-Host "Test type: $TestType" -ForegroundColor Cyan
Write-Host "----------------------------------------" -ForegroundColor Cyan
# Configure Pester
$config = New-PesterConfiguration
$config.Run.Path = Join-Path $PSScriptRoot "Tests"
$config.Output.Verbosity = "Detailed"
$config.Run.PassThru = $true
# Apply test filter if specified
if ($TestType -ne 'All') {
Write-Host "Running only $TestType tests..." -ForegroundColor Yellow
$config.Filter.Tag = @($TestType)
} else {
Write-Host "Running all tests..." -ForegroundColor Yellow
$config.Filter.Tag = @()
}
# Run tests
$testResults = Invoke-Pester -Configuration $config
# Display results summary
Write-Host "`nTest Results Summary:" -ForegroundColor Cyan
Write-Host "----------------------------------------" -ForegroundColor Cyan
Write-Host "Total Tests: $($testResults.TotalCount)" -ForegroundColor White
Write-Host "Passed: $($testResults.PassedCount)" -ForegroundColor Green
Write-Host "Failed: $($testResults.FailedCount)" -ForegroundColor Red
Write-Host "Skipped: $($testResults.SkippedCount)" -ForegroundColor Yellow
Write-Host "----------------------------------------" -ForegroundColor Cyan
if ($testResults.FailedCount -gt 0) {
Write-Host "`nFailed Tests:" -ForegroundColor Red
$testResults.Failed | ForEach-Object {
Write-Host "- $($_.Name)" -ForegroundColor Red
Write-Host " $($_.ErrorRecord)" -ForegroundColor Red
}
}
Write-Host "`nPress Enter to exit..." -ForegroundColor Green
$null = Read-Host