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>
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: System.Management.Automation.ScriptBlock
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: 1
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
INPUTS
OUTPUTS
NOTES
RELATED LINKS
VERSION
This page was generated using comment-based help in Pester 6.0.0.