BeforeEach
Contributions are welcome in Pester-repo.
SYNOPSIS​
Defines a series of steps to perform at the beginning of every It block within the current Context or Describe block.
SYNTAX​
BeforeEach [-Scriptblock] <ScriptBlock> [<CommonParameters>]
DESCRIPTION​
BeforeEach runs once before every test in the current or any child blocks. Typically this is used to create all the prerequisites for the current test, such as writing content to a file.
BeforeEach and AfterEach are unique in that they apply to the entire Context or Describe block, regardless of the order of the statements in the Context or Describe.
EXAMPLES​
EXAMPLE 1​
Describe "File parsing" {
BeforeEach {
# randomized path, to get fresh file for each test
$file = "$([IO.Path]::GetTempPath())/$([Guid]::NewGuid())_form.xml"
Copy-Item -Source $template -Destination $file -Force | Out-Null
}
It "Writes username" {
Write-XmlForm -Path $file -Field "username" -Value "nohwnd"
$content = Get-Content $file
# ...
}
It "Writes name" {
Write-XmlForm -Path $file -Field "name" -Value "Jakub"
$content = Get-Content $file
# ...
}
}
The example uses BeforeEach to ensure a clean sample-file is used for each test.
PARAMETERS​
-Scriptblock​
A scriptblock with steps to be executed during setup.
Type: ScriptBlock
Parameter Sets: (All)
Aliases:
Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters​
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
INPUTS​
OUTPUTS​
NOTES​
RELATED LINKS​
https://pester.dev/docs/commands/BeforeEach
https://pester.dev/docs/usage/setup-and-teardown
VERSION​
This page was generated using comment-based help in Pester 6.0.0-alpha5.