The Invoke-Pester
command makes it possible to invoke a single test script with explicit parameters using the -Script
parameter. But what if I want to pass the same parameters to all of the test scripts?
I do not want to invoke pester in a loop, because I want it to produce a single test result file.
So, how do we do it?
Starting from Pester 5.1 you can use New-PesterContainer -Data @{}
to pass all required parameters to Invoke-Pester
.
You can pass now path to both a single test file or a test directory to Invoke-Pester -Path
.
For instance, you have a test file:
param($param1, $param2)
Describe '' {
It '' {
$param1 | Should -Be '...'
$param2 | Should -Be '...'
}
}
Then you run it like this:
$container = New-PesterContainer -Path <tests_directory> -Data @{ param1='...'; param2='...' }
Invoke-Pester -Container $container
The official documentation is here: https://pester.dev/docs/usage/data-driven-tests#providing-external-data-to-tests
The list of new features you can find here: https://github.com/pester/Pester/releases/tag/5.1.0
You can do it by passing an array of hashes to the -Script
parameter. Something like this:
$a = @()
$params = @{param1 = 'xx'; param2 = 'wuauserv'}
$a += @{Path = '.\test1.Tests.ps1'; Parameters = $params}
$a += @{Path = '.\test2.Tests.ps1'; Parameters = $params}
Invoke-Pester -Script $a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With