Vous pouvez obtenir le nombre de tests ayant échoué en utilisant la fonction -PassThru
allumer Invoke-Pester
. Par exemple :
$TestResults = Invoke-Pester -PassThru
Mon $TestResults
La variable a alors un FailedCount
avec le nombre de tests qui ont échoué. Vous pouvez ensuite l'utiliser dans le cadre d'un pipeline pour que celui-ci échoue en cas d'échec des tests :
If ($TestResults.FailedCount -gt 0) { Throw "There were $($TestResults.FailedCount) failed tests" }
Voici un exemple des autres choses -PassThru
retours :
TagFilter :
ExcludeTagFilter :
TestNameFilter :
ScriptBlockFilter :
TotalCount : 230
PassedCount : 229
FailedCount : 1
SkippedCount : 0
PendingCount : 0
InconclusiveCount : 0
Time : 00:00:43.8675480
TestResult : {@{ErrorRecord=; ParameterizedSuiteName=; Describe=Testing all Modules against default
PSScriptAnalyzer rule-set; Parameters=System.Collections.Specialized.OrderedDictionary;
Passed=True; Show=All; FailureMessage=; Time=00:00:00.7463377; Name=passes the PSScriptAnalyzer
Rule PSAlignAssignmentStatement; Result=Passed; Context=Testing Module
'C:\Users\wragg\github\PowerShell-Subnet\Subnet\Subnet.psm1'; StackTrace=}, @{ErrorRecord=;
ParameterizedSuiteName=; Describe=Testing all Modules against default PSScriptAnalyzer rule-set;
Parameters=System.Collections.Specialized.OrderedDictionary; Passed=True; Show=All;
FailureMessage=; Time=00:00:02.2605400; Name=passes the PSScriptAnalyzer Rule
PSAvoidUsingCmdletAliases; Result=Passed; Context=Testing Module
'C:\Users\wragg\github\PowerShell-Subnet\Subnet\Subnet.psm1'; StackTrace=}, @{ErrorRecord=;
ParameterizedSuiteName=; Describe=Testing all Modules against default PSScriptAnalyzer rule-set;
Parameters=System.Collections.Specialized.OrderedDictionary; Passed=True; Show=All;
FailureMessage=; Time=00:00:00.0865224; Name=passes the PSScriptAnalyzer Rule
PSAvoidAssignmentToAutomaticVariable; Result=Passed; Context=Testing Module
'C:\Users\wragg\github\PowerShell-Subnet\Subnet\Subnet.psm1'; StackTrace=}, @{ErrorRecord=;
ParameterizedSuiteName=; Describe=Testing all Modules against default PSScriptAnalyzer rule-set;
Parameters=System.Collections.Specialized.OrderedDictionary; Passed=True; Show=All;
FailureMessage=; Time=00:00:00.0590095; Name=passes the PSScriptAnalyzer Rule
PSAvoidDefaultValueSwitchParameter; Result=Passed; Context=Testing Module
'C:\Users\wragg\github\PowerShell-Subnet\Subnet\Subnet.psm1'; StackTrace=}...}