pester-migration

Migrates PowerShell Pester test suites across major versions v3 through v6.

38.5k|4.9k|Updated Jun 11, 2025
One-click install
npx skills add https://github.com/github/awesome-copilot --skill pester-migration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pester-migration
Source: https://github.com/github/awesome-copilot/tree/main/skills/pester-migration
Command: npx skills add https://github.com/github/awesome-copilot --skill pester-migration

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Upgrading Pester test suites across major versions breaks existing tests in non-obvious ways — the v4→v5 Discovery/Run split silently nulls variables, mock assertions get renamed or removed, and legacy Invoke-Pester parameters stop working. This Skill provides version-detection heuristics, a step-by-step migration workflow, and symptom-to-fix tables so suites get green again without changing what they assert.

Core Features & Use Cases

  • Version Detection Heuristics: Identify which Pester version a suite was written for from syntax patterns like Should Be, $MyInvocation.MyCommand.Path, or Assert-MockCalled.
  • Per-Jump Migration Guides: Detailed references for v3→v4 (syntax renames), v4→v5 (Discovery/Run restructuring, BeforeAll, $PSScriptRoot, -ForEach), and v5→v6 (breaking changes like removed mock fall-through and empty -ForEach throwing).
  • Invoke-Pester Parameter Mapping: Convert legacy v4 parameters (-Script, -OutputFile, -CodeCoverage) to the New-PesterConfiguration object model.
  • Use Case: A CI pipeline fails after bumping Pester from 4 to 5 because setup code at the top of *.Tests.ps1 files runs during Discovery instead of Run. The Skill walks you through moving imports into BeforeAll, converting foreach-generated tests to -ForEach, and re-running until the suite matches its baseline.

Quick Start

Migrate my Pester test suite in the tests folder from version 4 to version 5 and fix any failures.

Frequently Asked Questions about pester-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate Pester tests from v4 to v5?

Move file imports into BeforeAll using $PSScriptRoot instead of $MyInvocation.MyCommand.Path, move test-generating code into BeforeDiscovery, and convert foreach-generated tests to -ForEach. Then convert Invoke-Pester legacy parameters to New-PesterConfiguration and re-run with -Output Diagnostic.

How do I upgrade Pester tests from v3 to v4?

Convert bareword assertions like Should Be to the dashed form Should -Be, rename Should Contain to Should -FileContentMatch, and rename Assert-VerifiableMocks to Assert-VerifiableMock. An AST-based converter script can automate the dash insertion, but review the diff and preserve file encoding.

Why are my Pester v5 variables null after migrating from v4?

Pester v5 splits runs into Discovery and Run phases, so code at the top of a test file or loose in a Describe body executes during Discovery and its variables are unavailable during Run. Move setup into BeforeAll and data generation into BeforeDiscovery.

What replaced Assert-MockCalled in Pester 6?

Assert-MockCalled was replaced by Should -Invoke, and Assert-VerifiableMock by Should -InvokeVerifiable. Both old cmdlets were deprecated in v5 and removed entirely in v6, so rename them during migration.

Can I skip a Pester major version when migrating?

No, migrate one major version at a time — go v4 to v5, then v5 to v6. Each jump has a different character, and skipping versions makes it impossible to match failures to documented breaking changes.

Why does Pester 6 throw on empty -ForEach data?

Pester 6 throws when -ForEach or -TestCases receives null or an empty array to catch bugs where data failed to load in BeforeDiscovery. Add -AllowNullOrEmptyForEach to blocks where empty data is legitimately expected.