See also: https://github.com/pester/Pester/discussions/2404#discussioncomment-7597861
I'm trying to set up tests using Pester with both external and non-external data. I've created separate test files for these scenarios and used Invoke-Pester with containers, but I'm facing a couple of issues:
Split Summaries: When I run the tests with external data, the summaries are split, and it doesn't provide a clear overall picture of test results.
Tests Passed: 1, Failed: 1, Skipped: 0 NotRun: 0
...
Tests Passed: 1, Failed: 0, Skipped: 0 NotRun: 0
rather than
Tests Passed: 2, Failed: 1, Skipped: 0 NotRun: 0
Passing Configuration: I'm unsure how to pass a configuration (-Configuration) into the inner Invoke-Pester call (Invoke-ExternalData.Tests.ps1
)
Here's the structure I'm using:
NonDataExternal.Tests.ps1:
Describe "behaviour" {
It "should be able to access the parameter" {
"value" | Should -Be "value"
}
}
ExternalData.ps1:
param(
[Parameter(Mandatory)]
$Param
)
Describe "behaviour" {
It "should be able to access the parameter" {
$Param | Should -Be "value"
}
}
Invoke-ExternalData.Tests.ps1:
$values = 'value', 'not value'
$containers = $values | ForEach-Object {
New-PesterContainer -Path "$PSScriptRoot/ExternalData.ps1" -Data @{ Param = $_ }
}
Invoke-Pester -Container $containers
I would appreciate guidance on how to structure these tests to achieve a unified summary and how to pass a configuration into the inner Invoke-Pester call. Is there a way to "hand-off" the PesterContainer objects without invoking Pester again?
My solution is to change
ExternalData.ps1
andInvoke-ExternalData.Tests.ps1
-ForEach
essentially injects the variables that are available in discovery to the Run phase ExternalData.ps1Invoke-ExternalData.Tests.ps1