Skip to main content
Version: v6

New-PesterContainer

This page was generated

Contributions are welcome in Pester-repo.

SYNOPSIS

Generates ContainerInfo-objects used as for Invoke-Pester -Container

SYNTAX

Path (Default)

New-PesterContainer -Path <string[]> [-Data <IDictionary[]>]

ScriptBlock

New-PesterContainer -ScriptBlock <scriptblock[]> [-Data <IDictionary[]>]

DESCRIPTION

Pester 5 supports running tests files and scriptblocks using parameter-input. To use this feature, Invoke-Pester expects one or more ContainerInfo-objects created using this function, that specify test containers in the form of paths to the test files or scriptblocks containing the tests directly.

A optional Data-dictionary can be provided to supply the containers with any required parameter-values. This is useful in when tests are generated dynamically based on parameter-input. This method enables complex test-solutions while being able to re-use a lot of test-code.

EXAMPLES

EXAMPLE 1

$container = New-PesterContainer -Path 'CodingStyle.Tests.ps1' -Data @{ File = "Get-Emoji.ps1" }
Invoke-Pester -Container $container

This example runs Pester using a generated ContainerInfo-object referencing a file and required parameters that's provided to the test-file during execution.

EXAMPLE 2

$sb = {
Describe 'Testing New-PesterContainer' {
It 'Useless test' {
"foo" | Should -Not -Be "bar"
}
}
}
$container = New-PesterContainer -ScriptBlock $sb
Invoke-Pester -Container $container

This example runs Pester against a scriptblock. New-PesterContainer is used to generate the required ContainerInfo-object that enables us to do this directly.

PARAMETERS

-Data

Allows a dictionary to be provided with parameter-values that should be used during execution of the test containers defined in Path or ScriptBlock.

Type: System.Collections.IDictionary[]
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Path

Specifies one or more paths to files containing tests. The value is a path\file name or name pattern. Wildcards are permitted.

Type: System.String[]
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Path
Position: Named
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-ScriptBlock

Specifies one or more scriptblocks containing tests.

Type: System.Management.Automation.ScriptBlock[]
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: ScriptBlock
Position: Named
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

Pester.ContainerInfo

NOTES

VERSION

This page was generated using comment-based help in Pester 6.0.0.