Pester tests with dynamic names result in no output from Invoke-OperationValidation
The following results in no output:
Invoke-OperationValidation -ModuleName tervisactivedirectory -IncludePesterOutput
File Simple.tests.ps1 in TervisActiveDirectory\Diagnostics\Simple
$ADUsers = Get-ADUser -Filter * -SearchBase "OU=Departments,DC=tervis,DC=prv" -Properties HomeDirectory, Manager, EmployeeID
foreach ($ADUser in $ADUsers) {
Describe "Active Directory User $($ADUser.Name) ($($ADUser.samaccountname))" {
It "Has an employee ID" {
$ADUSer.EmployeeID | Should Not BeNullOrEmpty
}
It "Has a manager set" {
$ADUSer.Manager | Should Not BeNullOrEmpty
}
}
}
Running directly Invoke-Pester without using OVF works and results in the output of the pester tests with the Describe statement dynamically including the name of the AD user being tested.
I think the problem is with line 375 of OperationValidation.psm1:
$testResult = Invoke-pester -Path $ti.FilePath -TestName $tName -quiet:$quiet -PassThru
The $tName variable contains "Active Directory User $($ADUser.Name) ($($ADUser.samaccountname))" and pester isn't able to find and run that named test.
This is because OVF is inspecting the Pester test and parsing the contents of the script not actually executing it. This function is how OVF determines the name for the Describe block.
Since OVF doesn't actually execute the Pester script when it searches for test names, there is no way for it to handle expressions in the Describe block like your case above.
You CAN however generate dynamic names for your Context blocks since OVF doesn't not deal with those directly.
Describe 'This is a static describe name' {
(1..10) | ForEach-Object {
context "This is dynamic test number [$_]" {
it 'Always works' {
$true | should be $true
}
}
}
}