
Pester Should Migration
OfficialFreeEasily convert Pester v5 assertions to v6 syntax.
Free · Opens the source repo
What Pester Should Migration does
The Pester Should Migration skill provides a straightforward method for developers to transition their PowerShell test suites from the classic Pester v5 assertion syntax to the new Pester v6 Should-* assertion format. This skill is particularly useful for those looking to modernize their test code and take advantage of the enhanced features and clearer error messages offered by the new syntax. The migration process is designed to be incremental, allowing users to convert assertions one at a time without breaking existing tests, as both syntaxes can coexist in Pester v6.
Using this skill, developers can easily identify classic assertions in their PowerShell test files and apply the necessary transformations to update them to the new format. The skill includes a mapping of common assertions, making it easy to see what the equivalent new assertion looks like. For example, converting Should -Be to Should-Be or Should -Not -Be to Should-NotBe is a mechanical change that can be done with minimal effort. However, the skill also emphasizes the importance of checking for behavioral differences that may arise from the migration, ensuring that tests remain valid after conversion.
This skill is aimed at PowerShell developers who are currently using Pester for testing and want to keep their test suites up to date with the latest standards. It is especially beneficial for teams working on long-term projects where maintaining a clean and modern codebase is essential. By adopting the new Should-* assertions, developers can also benefit from improved type-awareness and clearer failure messages, which can enhance the debugging process.
It's important to note that while this skill facilitates the migration to the new syntax, it does not enforce it. Users can choose to retain classic assertions as needed, making the transition flexible according to their project's requirements. The skill also provides guidance on how to verify that tests remain green after migration, ensuring that the integrity of the test suite is preserved throughout the process.
When to use it
Use this skill when modernizing a Pester test suite to utilize the new `Should-*` assertions or when converting existing `Should -...` calls in PowerShell test files.
When not to use it
This skill is not suitable if you are not using Pester v6 or if you do not need to migrate assertions from the classic syntax.
What you can build with it
Modernizing Test Suites
Use this skill to update legacy Pester v5 assertions in your test files to the new v6 syntax for better clarity.
Incremental Migration
Migrate your test assertions gradually, converting one assertion at a time while keeping the suite green.
Improving Error Messages
Adopt the new `Should-*` assertions to benefit from clearer, type-aware failure messages during testing.
How to install Pester Should Migration
View source1. Install with the skills CLI
npx skills add github/awesome-copilot/pester-should-migration --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by githubPester Should -* → Should-* Migration
Convert classic Pester v5 assertions (Should -Be, space then parameter) to the
new Pester v6 Should-* assertions (Should-Be, hyphen, no space).
Status: experimental / preview. Verified against Pester 6.0.0-rc2. The classic
Should -Bestyle still works in v6, so migrate incrementally and keep the suite green.
Companion skill. This skill covers the optional move to the new
Should-*operators. To upgrade a suite across major Pester versions (v3→v4→v5→v6 — the runtime, mocks, and config), use the separate pester-migration skill. In v6 the classicShould -Bekeeps working, so adoptingShould-*is independent of any version bump.
When to Use
- Modernizing a Pester suite to the v6
Should-*assertions. - A user asks to migrate / convert / rewrite
Should -...calls. - You want clearer, type-aware failure messages from the new assertions.
Know This First
- Both syntaxes work side by side in Pester v6. Migration is optional and can be done one test (or one file) at a time. Nothing breaks if you leave some classic.
- Requires Pester v6+. The
Should-*commands do not exist in v5. - Negation is a separate command, not a
-Notswitch:Should -Not -Be→Should-NotBe. There is no-Notparameter on the new assertions. - The actual value still comes from the pipeline (
$x | Should-Be 1) or from-Actual(Should-Be -Actual $x -Expected 1).-Becausecarries over unchanged. - Most renames are mechanical, but several have behavior changes you must check by hand — see Gotchas.
Procedure
Step 1 — Find the classic assertions
Search the target for the classic space-separated syntax (the tell is Should -,
or Should followed by -Not):
Should - # any classic operator
Should -Not - # negated classic operator
Assert-MockCalled # also removed in v6 -> Should-Invoke
Limit the scope to PowerShell test files (*.Tests.ps1, *.ps1).
Step 2 — Apply the mapping
Most-used conversions (full list in references/assertion-map.md):
| Classic (v5) | New (v6) |
|---|---|
$x | Should -Be 1 | $x | Should-Be 1 |
$x | Should -Not -Be 1 | $x | Should-NotBe 1 |
$x | Should -BeExactly 'A' | $x | Should-BeString 'A' -CaseSensitive |
$x | Should -BeGreaterOrEqual 2 | $x | Should-BeGreaterThanOrEqual 2 |
$x | Should -BeLessOrEqual 2 | $x | Should-BeLessThanOrEqual 2 |
$x | Should -BeLike 'a*' | $x | Should-BeLikeString 'a*' |
$x | Should -Match 're' | $x | Should-MatchString 're' |
$x | Should -BeOfType [int] | $x | Should-HaveType ([int]) |
$x | Should -BeNullOrEmpty | depends — see gotchas (no single equivalent) |
$c | Should -HaveCount 3 | $c | Should-BeCollection -Count 3 |
$c | Should -Contain 2 | $c | Should-ContainCollection 2 |
{ ... } | Should -Throw 'msg' | { ... } | Should-Throw -ExceptionMessage 'msg' |
Should -Invoke Get-Thing | Should-Invoke Get-Thing |
Should -InvokeVerifiable | Should-Invoke -Verifiable |
Step 3 — Check the behavioral gotchas (do NOT skip)
These do not translate by a plain rename. Read each before converting:
- Case sensitivity. Classic
Should -Beis case-insensitive on strings; so isShould-Be. But classicShould -BeExactly(case-sensitive) has no plain equivalent — useShould-BeString -CaseSensitive. (Should-Beis never case-sensitive.) Same pattern forBeLikeExactly→Should-BeLikeString -CaseSensitiveandMatchExactly→Should-MatchString -CaseSensitive. - Truthy vs. true. Classic
Should -BeTrue/-BeFalseaccept any truthy / falsy value (1,'x',0,'',$null,@()). The newShould-BeTrue/Should-BeFalseare strict (exactly$true/$false). To preserve the old loose behavior useShould-BeTruthy/Should-BeFalsy. Only use the strict ones when the value really is a boolean. BeNullOrEmptyhas no single equivalent. Pick by intent:$null→Should-BeNull; empty string →Should-BeEmptyString; empty collection →Should-BeCollection -Count 0; broad "falsy" →Should-BeFalsy. The negationShould -Not -BeNullOrEmptysimilarly splits intoShould-NotBeNull/Should-NotBeEmptyString/Should-NotBeWhiteSpaceString.- Collections. Classic
Should -Bealso compares arrays; the newShould-Beis a value assertion and errors if-Expectedis a collection ("You provided a collection to the -Expected parameter"). UseShould-BeCollectionto compare arrays.Should -Contain(single-item membership) →Should-ContainCollection. The new command also takes a collection of expected items and checks they are all present, in the right order (1, 2, 3 | Should-ContainCollection @(1, 2)). For exact, whole-collection equality useShould-BeCollectioninstead. - Pipeline unwrapping. The pipeline unwraps input: a value assertion sees
@(1)as1and@()as$null, and a typed collection ([int[]]) is re-collected as[object[]]. When the exact value or concrete collection type matters (e.g.Should-HaveType), pass it with-Actualinstead of piping. - No
Should-*equivalent.Should -Existand theShould -FileContentMatch*family have no new counterpart. Either keep the classic assertion, or rewrite with PowerShell:Test-Path $p | Should-BeTrue,(Get-Content $p -Raw) | Should-MatchString 're'. Should -BeIndirection. NoShould-BeIn. Reverse the operands:$value | Should -BeIn $collection→$collection | Should-ContainCollection $value(note the actual/expected swap), or keep the classic form.
Step 4 — Verify
Run the suite and confirm it's still green — the new messages differ, but passes must stay passes:
Invoke-Pester -Path ./tests
If a converted assertion newly fails, re-check the gotchas above (most often #2 truthy/falsy, #3 null-or-empty, or #4 collections).
Step 5 — (Optional) Enforce the new style
Once a suite is fully migrated, switch off the classic syntax so it can't creep back:
$config = New-PesterConfiguration
$config.Should.DisableV5 = $true
With this set, any remaining Should -Be throws and points at the Should-Be form.
Output
Summarize what changed: files touched, count of assertions converted, any classic
assertions intentionally left (e.g. Should -Exist), and any conversions that need
a human decision (truthy/falsy, null-or-empty, collection semantics).
Reference
- references/assertion-map.md — full operator-by-operator table with before/after examples and workarounds.
- Live command reference:
https://pester.dev/docs/commands/Should-Be(swap in anyShould-*name) for exact parameters and examples. - Concepts:
https://pester.dev/docs/assertions/should-command(value vs. collection assertions, pipeline vs.-Actual). - v5→v6 upgrade guide:
https://pester.dev/docs/migrations/v5-to-v6.
Frequently asked questions about Pester Should Migration
Similar skills
React Composition Patterns
Streamline your React component architecture with proven patterns.
Radix to Base UI Migration
Seamlessly migrate React components from Radix UI to Base UI.
Migrate Next.js to Vinext
Seamlessly transition your Next.js projects to Vinext.
WinUI 3 Migration Guide
Streamline your UWP to WinUI 3 migration process.
Refactor
Enhance code maintainability without altering behavior.
React 18 Lifecycle Patterns
Migrate unsafe React lifecycle methods with precision.
