1
1
param (
2
- [ValidateSet (' None' , ' Default' , ' Passed' , ' Failed' , ' Pending' , ' Skipped' , ' Inconclusive' , ' Describe' , ' Context' , ' Summary' , ' Header' , ' Fails' , ' All' )]
3
- [string ]
4
- $Show = " None" ,
5
-
6
- [ValidateSet (' Everything' , ' Functions' , ' General' )]
7
- [string ]
8
- $Run = " Everything" ,
9
-
10
- [string ]
11
- $Filter = " *.Tests.ps1"
2
+ [ValidateSet (' None' , ' Default' , ' Passed' , ' Failed' , ' Pending' , ' Skipped' , ' Inconclusive' , ' Describe' , ' Context' , ' Summary' , ' Header' , ' Fails' , ' All' )]
3
+ [string ]
4
+ $Show = " None" ,
5
+
6
+ [ValidateSet (' Everything' , ' Functions' , ' General' )]
7
+ [string ]
8
+ $Run = " Everything" ,
9
+
10
+ [string ]
11
+ $Filter = " *.Tests.ps1"
12
12
)
13
13
14
- Write-Host " Starting Tests" - ForegroundColor Green
14
+ Write-PSFMessage - Level Host - Message " Starting Tests"
15
15
16
- Write-Host " Importing Module" - ForegroundColor Cyan
16
+ Write-PSFMessage - Level Host - Message " Importing Module"
17
17
18
18
Remove-Module PSModuleDevelopment - ErrorAction Ignore
19
19
Import-Module " $PSScriptRoot \..\PSModuleDevelopment.psd1"
20
20
Import-Module " $PSScriptRoot \..\PSModuleDevelopment.psm1" - Force
21
21
22
+ Write-PSFMessage - Level Host - Message " Creating test result folder"
23
+ $null = New-Item - Path " $PSScriptRoot \..\.." - Name TestResults - ItemType Directory - Force
24
+
22
25
$totalFailed = 0
23
26
$totalRun = 0
24
27
25
28
$testresults = @ ()
26
29
27
- if ($Run -match " Everything|General" )
28
- {
29
- Write-PSFMessage - Level Important - Message " Modules imported, proceeding with general tests"
30
- foreach ($file in (Get-ChildItem " $PSScriptRoot \general" - Filter $Filter ))
31
- {
32
- Write-PSFMessage - Level Significant - Message " Executing <c='em'>$ ( $file.Name ) </c>"
33
- $results = Invoke-Pester - Script $file.FullName - Show $Show - PassThru
34
- foreach ($result in $results )
35
- {
36
- $totalRun += $result.TotalCount
37
- $totalFailed += $result.FailedCount
38
- $result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
39
- $name = $_.Name
40
- $testresults += [pscustomobject ]@ {
41
- Describe = $_.Describe
42
- Context = $_.Context
43
- Name = " It $name "
44
- Result = $_.Result
45
- Message = $_.FailureMessage
46
- }
47
- }
48
- }
49
- }
30
+ if ($Run -match " Everything|General" ) {
31
+ Write-PSFMessage - Level Important - Message " Modules imported, proceeding with general tests"
32
+ foreach ($file in (Get-ChildItem " $PSScriptRoot \general" - Filter $Filter )) {
33
+ Write-PSFMessage - Level Significant - Message " Executing <c='em'>$ ( $file.Name ) </c>"
34
+ $TestOuputFile = Join-Path " $PSScriptRoot \..\..\TestResults" " TEST-$ ( $file.BaseName ) .xml"
35
+ $results = Invoke-Pester - Script $file.FullName - Show $Show - PassThru - OutputFile $TestOuputFile - OutputFormat NUnitXml
36
+ foreach ($result in $results ) {
37
+ $totalRun += $result.TotalCount
38
+ $totalFailed += $result.FailedCount
39
+ $result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
40
+ $name = $_.Name
41
+ $testresults += [pscustomobject ]@ {
42
+ Describe = $_.Describe
43
+ Context = $_.Context
44
+ Name = " It $name "
45
+ Result = $_.Result
46
+ Message = $_.FailureMessage
47
+ }
48
+ }
49
+ }
50
+ }
50
51
}
51
52
52
- if ($Run -match " Everything|Functions" )
53
- {
54
- Write-PSFMessage - Level Important - Message " Proceeding with individual tests"
55
- foreach ($file in (Get-ChildItem " $PSScriptRoot \functions" - Recurse - File - Filter $Filter ))
56
- {
57
- Write-PSFMessage - Level Significant - Message " Executing $ ( $file.Name ) "
58
- $results = Invoke-Pester - Script $file.FullName - Show $Show - PassThru
59
- foreach ($result in $results )
60
- {
61
- $totalRun += $result.TotalCount
62
- $totalFailed += $result.FailedCount
63
- $result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
64
- $name = $_.Name
65
- $testresults += [pscustomobject ]@ {
66
- Describe = $_.Describe
67
- Context = $_.Context
68
- Name = " It $name "
69
- Result = $_.Result
70
- Message = $_.FailureMessage
71
- }
72
- }
73
- }
74
- }
53
+ if ($Run -match " Everything|Functions" ) {
54
+ Write-PSFMessage - Level Important - Message " Proceeding with individual tests"
55
+ foreach ($file in (Get-ChildItem " $PSScriptRoot \functions" - Recurse - File - Filter $Filter )) {
56
+ Write-PSFMessage - Level Significant - Message " Executing $ ( $file.Name ) "
57
+ $results = Invoke-Pester - Script $file.FullName - Show $Show - PassThru
58
+ foreach ($result in $results ) {
59
+ $totalRun += $result.TotalCount
60
+ $totalFailed += $result.FailedCount
61
+ $result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
62
+ $name = $_.Name
63
+ $testresults += [pscustomobject ]@ {
64
+ Describe = $_.Describe
65
+ Context = $_.Context
66
+ Name = " It $name "
67
+ Result = $_.Result
68
+ Message = $_.FailureMessage
69
+ }
70
+ }
71
+ }
72
+ }
75
73
}
76
74
77
75
$testresults | Sort-Object Describe, Context, Name, Result, Message | Format-List
78
76
79
77
if ($totalFailed -eq 0 ) { Write-PSFMessage - Level Critical - Message " All <c='em'>$totalRun </c> tests executed without a single failure!" }
80
78
else { Write-PSFMessage - Level Critical - Message " <c='em'>$totalFailed tests</c> out of <c='sub'>$totalRun </c> tests failed!" }
81
79
82
- if ($totalFailed -gt 0 )
83
- {
84
- throw " $totalFailed / $totalRun tests failed!"
85
- }
80
+ if ($totalFailed -gt 0 ) {
81
+ throw " $totalFailed / $totalRun tests failed!"
82
+ }
0 commit comments