external help file | Module Name | online version | schema |
---|---|---|---|
Pester-help.xml |
Pester |
2.0.0 |
Defines a series of steps to perform at the end of the current container, Context or Describe block.
AfterAll [-Scriptblock] <ScriptBlock> [<CommonParameters>]
AfterAll is used to share teardown after all the tests in a container, Describe or Context including all child blocks and tests. AfterAll runs during Run phase and runs only once in the current block. It's guaranteed to run even if tests fail.
The typical usage is to clean up state or temporary used in tests.
BeforeAll and AfterAll are unique in that they apply to the entire container, Context or Describe block regardless of the order of the statements compared to other Context or Describe blocks at the same level.
```powershell
Describe "Validate important file" {
BeforeAll {
$samplePath = "$([IO.Path]::GetTempPath())/$([Guid]::NewGuid()).txt"
Write-Host $samplePath
1..100 | Set-Content -Path $samplePath
}
It "File Contains 100 lines" { @(Get-Content $samplePath).Count | Should -Be 100 }
It "First ten lines should be 1 -\> 10" {
@(Get-Content $samplePath -TotalCount 10) | Should -Be @(1..10)
}
AfterAll {
Remove-Item -Path $samplePath
}
} ```
This example uses AfterAll to clean up a sample-file generated only for the tests in the Describe-block.
A scriptblock with steps to be executed during teardown.
Type: ScriptBlock
Parameter Sets: (All)
Aliases:
Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.