alpha

Sets rules for writing PowerShell tests with Pester v6: file layout, test structure, discovery and run, mocking and configuration.
applyTo: '**/*.Tests.ps1'
description: 'PowerShell Pester testing best practices based on Pester v6 conventions'
This guide provides PowerShell-specific instructions for creating automated tests with the PowerShell Pester v6 module. Pester v6 runs on Windows PowerShell 5.1 and PowerShell 7.4+. Follow the general PowerShell scripting guidance in [powershell.instructions.md](./powershell.instructions.md).
Pester v6 is largely compatible with v5, but it makes several previously deprecated behaviours fail fast. Keep each test file self-contained and run the suite with the same PowerShell and Pester versions used by CI.
*.Tests.ps1 naming patternBeforeAll { . $PSScriptRoot/FunctionName.ps1 } to import tested functionsBeforeAll, Describe, Context, It, etc.)BeforeAll { # Import tested functions }
Describe 'FunctionName' {
Context 'When condition' {
BeforeAll { # Setup for context }
It 'Should behavior' { # Individual test }
AfterAll { # Cleanup for context }
}
}
BeforeDiscovery for data needed to construct tests and BeforeAll to import modules or initialise runtime state for the file.Run.BeforeContainer) or a repository Pester.BeforeContainer.ps1 when it truly applies to all files.BeforeDiscovery {
$cases = Get-Content "$PSScriptRoot/cases.json" | ConvertFrom-Json
}
BeforeAll {
Import-Module "$PSScriptRoot/MyModule.psm1"
}
Describe 'MyModule' {
It 'handles <Name>' -ForEach $cases { Invoke-Thing $Name | Should -Be 'ok' }
}
Describe: Top-level grouping, typically named after function being testedContext: Sub-grouping within Describe for specific scenariosIt: Individual test cases, use descriptive namesShould: Classic assertion command (Should -Be, Should -Throw, etc.); existing v5 syntax remains supportedShould-*: New v6 assertion commands (Should-Be, Should-Throw, etc.); adopt them deliberately, not as a required renameBeforeAll/AfterAll: Setup/teardown once per blockBeforeEach/AfterEach: Setup/teardown before/after each testBeforeAll: Runs once at start of containing block, use for expensive operationsBeforeEach: Runs before every It in block, use for test-specific setupAfterEach: Runs after every It, guaranteed even if test failsAfterAll: Runs once at end of block, use for cleanupBeforeAll variables are available to child blocks (read-only); BeforeEach, It, and AfterEach share their block scopeBeforeAll, BeforeEach, AfterAll, or AfterEach; combine setup when necessary-Be, -BeExactly, -Not -Be-Contain, -BeIn, -HaveCount-BeGreaterThan, -BeLessThan, -BeGreaterOrEqual-Match, -Like, -BeNullOrEmpty-BeOfType, -BeTrue, -BeFalse-Exist, -FileContentMatch-Throw, -Not -ThrowMock CommandName { ScriptBlock }: Replace command behavior-ParameterFilter: Mock only when parameters match condition-Verifiable: Mark mock as requiring verificationShould -Invoke: Verify mock was called specific number of timesShould -InvokeVerifiable: Verify all verifiable mocks were calledPester v6 removes Assert-MockCalled and Assert-VerifiableMock; replace them with the Should -Invoke forms. Calls that miss every -ParameterFilter no longer fall through to the real command, so add a default mock whenever unmatched calls are valid.
Mock Get-Service { @{ Status = 'Running' } } -ParameterFilter { $Name -eq 'TestService' }
Should -Invoke Get-Service -Exactly 1 -ParameterFilter { $Name -eq 'TestService' }
Use -TestCases or -ForEach for parameterized tests. In Pester v6, $null or an empty array throws instead of silently skipping; fix the data source or opt in to an empty case with -AllowNullOrEmptyForEach on the specific block.
It 'Should return <Expected> for <Input>' -TestCases @(
@{ Input = 'value1'; Expected = 'result1' }
@{ Input = 'value2'; Expected = 'result2' }
) {
Get-Function $Input | Should -Be $Expected
}
-ForEach: Available on Describe, Context, and It for generating multiple tests from data-TestCases: Alias for -ForEach on It blocks (backwards compatibility)@{ Name = 'value'; Expected = 'result' })$_ variable for current item<variablename> in test names for dynamic expansion# Hashtable approach
It 'Returns <Expected> for <Name>' -ForEach @(
@{ Name = 'test1'; Expected = 'result1' }
@{ Name = 'test2'; Expected = 'result2' }
) { Get-Function $Name | Should -Be $Expected }
# Array approach
It 'Contains <_>' -ForEach 'item1', 'item2' { Get-Collection | Should -Contain $_ }
When a test name contains <...>, Pester v6 evaluates the token as a PowerShell expression. Backtick-escape the opening < when the text should remain literal.
Describe, Context, and It blocks-Tag and -ExcludeTag with Invoke-Pester, or set Filter.Tag and Filter.ExcludeTag in New-PesterConfiguration-like wildcards for flexible filteringDescribe 'Function' -Tag 'Unit' {
It 'Should work' -Tag 'Fast', 'Stable' { }
It 'Should be slow' -Tag 'Slow', 'Integration' { }
}
# Run only fast unit tests
Invoke-Pester -Tag 'Unit' -ExcludeTag 'Slow'
-Skip: Available on Describe, Context, and It to skip tests-Skip:$condition for dynamic skippingSet-ItResult -Skipped or Set-ItResult -Inconclusive during test execution (setup/teardown still run)Set-ItResult -Skipped/-Inconclusive throws internally to end the It block, so code after it does not run; a trailing return is unreachable and should not be addedIt 'Should work on Windows' -Skip:(-not $IsWindows) { }
Context 'Integration tests' -Skip { }
Should.ErrorAction = 'Continue' to collect multiple failures-ErrorAction Stop for pre-conditions{ Code } | Should -Throw for exception testingSet-ItResult -Pending was removed; use -Inconclusive, -Skipped, or It -SkipWhere-Object not ?)BeforeAll {
. $PSScriptRoot/Get-UserInfo.ps1
}
Describe 'Get-UserInfo' {
Context 'When user exists' {
BeforeAll {
Mock Get-ADUser { @{ Name = 'TestUser'; Enabled = $true } }
}
It 'Should return user object' {
$result = Get-UserInfo -Username 'TestUser'
$result | Should -Not -BeNullOrEmpty
$result.Name | Should -Be 'TestUser'
}
It 'Should call Get-ADUser once' {
Get-UserInfo -Username 'TestUser'
Should -Invoke Get-ADUser -Exactly 1
}
}
Context 'When user does not exist' {
BeforeAll {
Mock Get-ADUser { throw "User not found" }
}
It 'Should throw exception' {
{ Get-UserInfo -Username 'NonExistent' } | Should -Throw "*not found*"
}
}
}
Configuration is defined outside test files when calling Invoke-Pester to control execution behavior.
# Create configuration (Pester v6)
$config = New-PesterConfiguration
$config.Run.Path = './Tests'
$config.Output.Verbosity = 'Detailed'
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = 'NUnitXml'
$config.Should.ErrorAction = 'Continue'
Invoke-Pester -Configuration $config
Key Sections: Run (Path, Exit), Filter (Tag, ExcludeTag), Output (Verbosity), TestResult (Enabled, OutputFormat), CodeCoverage (Enabled, Path), Should (ErrorAction), Debug
© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com


Skater clears a stair set in one low tracking shot
Writes a 30-second continuous low tracking shot of a skateboarder clearing stairs at golden hour, in six-second beats with a locked face and outfit.
video-prompt, timed-beats, tracking-shot, single-take, camera-movement, action, sports, kling, character-consistency, golden-hour, low-angle, natural-light, wide-shot, photorealistic, cinematic, guardrails, for-filmmakers, man, full-body, slow-motion, structured-output

Four city outfit change with depth reference
Directs a 12-second vertical video where one woman spins through four city outfit changes, locked to outfit pictures, a face crop and a depth-video motion reference.
video-prompt, reference-image, character-consistency, face-reference, timed-beats, multi-shot, vertical-format, transformation, video-ad, travel, scene-transitions, camera-movement, fashion, cityscape, landmarks, short-form-video, long-form, structured-output, woman, fashion-shoot

Quiet Kyoto autumn travel vlog, 30 seconds
Generates a slow, natural 30-second autumn travel vlog in Kyoto of the woman from a reference image, with short casual dialogue, handheld camera and film grain, avoiding an ad look.
video-prompt, vlog, reference-image, character-consistency, handheld, film-grain, home-video, travel, japan, multi-shot, lip-sync, natural-light, guardrails, seedance, for-content-creators, timed-beats, long-form, casual, candid, autumn
Loading reviews…
Loading comments…