Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Pester tests with dynamic names result in no output from Invoke-OperationValidation #15

Open
ChrisMagnuson opened this issue Jan 20, 2017 · 1 comment
Labels

Comments

@ChrisMagnuson
Copy link

ChrisMagnuson commented Jan 20, 2017

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.

@devblackops
Copy link
Contributor

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
            }
        }
    }
}

@davidwallis davidwallis mentioned this issue Jun 27, 2017
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants