| name | pester-testing |
| description | Write idiomatic Pester 5 tests for PowerShell modules. Use this skill
whenever a user asks to add tests, fill coverage gaps, or validate AI-generated
PowerShell code. Targets Pester 5+ syntax (BeforeAll/Describe/It, no Pester 4
patterns).
|
| domain | powershell-testing |
| confidence | high |
| source | earned |
| tools | [] |
Context
Apply this skill when the user wants to write or extend Pester tests for a
PowerShell module. The user has already provided the module under test (or
will point you at it) and expects tests that follow Pester 5 conventions and
the project's existing style.
Patterns
- Pester 5 only. Use
BeforeAll, Describe, Context, It, Should -Be,
Should -Throw. Do not use Pester 4 patterns like In blocks or v4-style
mocks unless the user explicitly requests them.
- Test the module surface, not internals. Import via the
.psd1 manifest
and assert on ExportedFunctions, parameter validation, and output shape.
Prefer (Get-Module X).ExportedFunctions.Keys | Should -Be ... over reaching
into private functions.
- Validate parameter attributes at bind time.
{ Get-Foo -BadParam X } | Should -Throw proves the validator works without needing the function body
to run.
- Skip platform-specific tests on the wrong platform. Use
-Skip:(-not $IsWindows)
or -Skip:(-not $IsLinux) rather than wrapping in if. Skips show up in test
output; ifs disappear.
- One
BeforeAll to import the module at the file level, one AfterAll
to remove it. Don't import inside each Describe.
- Discover real gaps first. Before writing tests, scan the public functions
for: missing parameter-validation tests, missing shape tests, missing
error-case tests. Report the gap list, then offer to fill them.
Examples
Minimal Pester 5 file for a module:
#requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.0' }
BeforeAll {
$script:Manifest = Join-Path $PSScriptRoot '..\MyModule\MyModule.psd1' | Resolve-Path
Remove-Module MyModule -ErrorAction SilentlyContinue
Import-Module $script:Manifest -Force
}
AfterAll {
Remove-Module MyModule -ErrorAction SilentlyContinue
}
Describe 'MyModule surface' {
It 'exports the expected functions' {
(Get-Module MyModule).ExportedFunctions.Keys | Should -Be @('Get-Foo','Set-Foo')
}
}
Describe 'Get-Foo' {
It 'rejects an invalid value at bind time' {
{ Get-Foo -Status 'Bogus' } | Should -Throw
}
}
Anti-patterns
- Don't write tests that require the production target (real services, real
hosts) unless explicitly asked. Parameter-validation and shape tests run
anywhere.
- Don't use
-Verifiable mocks with Assert-VerifiableMock (Pester 5 prefers
Should -Invoke).
- Don't paste an entire generated test suite without first showing the
user a one-line summary of what gaps you found. They need to confirm the
scope before you fill it.