Chuyển đến nội dung
Skillpedia
Kiểm thử40k · #7318

pester-migration

Skill này làm gì

Công cụ này giúp cập nhật các test phần mềm của bạn (gọi là Pester) lên phiên bản PowerShell mới hơn. Nó điều chỉnh cách viết và chạy test để chúng hoạt động đúng với các phiên bản mới.

Khi nào nên dùng

  • ✓Khi bạn nâng cấp môi trường phát triển lên phiên bản PowerShell chính mới.
  • ✓Khi các test Pester cũ ngừng hoạt động sau một lần cập nhật.
  • ✓Khi bạn muốn các test phần mềm phù hợp với phiên bản công cụ mới nhất.

Liên kết skill

https://github.com/github/awesome-copilot/blob/main/skills/pester-migration/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/pester-migration/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Cập nhật các test Pester của tôi từ phiên bản 4 lên 5.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ phân tích các test hiện có và áp dụng các thay đổi cần thiết về cú pháp và cấu trúc. Nó tuân theo các hướng dẫn cụ thể cho từng lần cập nhật phiên bản, bảo đảm thay đổi được thực hiện đúng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Pester Migration

Pester is the test framework for PowerShell. Test files end in *.Tests.ps1 and use Describe / Context / It blocks with Should assertions. This skill upgrades an existing suite from one major Pester version to the next and gets it green again.

Mental model: each major jump has a different character. v3→v4 is mostly a syntax rename. v4→v5 is a fundamental runtime change (the Discovery/Run split) and is the hard one. v5→v6 is largely backwards-compatible — a handful of previously-deprecated things now throw. Migrate one major at a time; never skip a version.

Detailed, symptom-driven guides live in references/ — load the one(s) for the jump you are doing.

References

Reference When to load
v3-to-v4.md Should Be → Should -Be, Contain → FileContentMatch, Assert-VerifiableMocks → Assert-VerifiableMock, array-assertion edge cases.
v4-to-v5.md The big one. Discovery/Run phases, BeforeAll setup, $PSScriptRoot, BeforeDiscovery, -ForEach, mock scoping, Should -Throw wildcards, Invoke-Pester → New-PesterConfiguration.
v5-to-v6.md PowerShell 5.1/7.4+ only, per-file discovery+run, empty -ForEach throws, duplicate setup blocks throw, name <...> templates evaluate, Assert-MockCalled removed, mocks no longer fall through, code-coverage tracer, legacy Invoke-Pester params removed.

Canonical source: the official migration guides at https://pester.dev/docs/migrations/ — this skill mirrors them. When in doubt, prefer the website.

Step 0 — Detect where you are and where you're going

Find the installed version(s) and the version the tests were written for. These can differ.

# Installed Pester version(s) on this machine
Get-Module Pester -ListAvailable | Select-Object Name, Version, Path

# Version currently imported in the session
(Get-Module Pester).Version

Tell the source version from the test code with these heuristics:

You see in *.Tests.ps1 / build scripts Suite was written for
Should Be / Should Contain (no dash) v3 or earlier → start at v3-to-v4
$MyInvocation.MyCommand.Path + dot-source at the top of the file; arbitrary code directly under Describe v4 → v4-to-v5
Assert-MockCalled, Assert-VerifiableMock, Set-ItResult -Pending v4 / early-v5 (these are removed in v6)
Invoke-Pester -Script … -OutputFile … -CodeCoverage … (legacy params) v4 invocation → map to config
BeforeAll { . $PSScriptRoot/… }, New-PesterConfiguration, Should -Invoke already v5-style → v5-to-v6

Install the target version when ready:

# Latest stable v5 — pin the major to avoid installing Pester 6
Install-Module Pester -MaximumVersion 5.99.99 -Force

# Pester 6
Install-Module Pester -Force

On Windows PowerShell 5.1 the OS ships a Microsoft-signed built-in Pester 3 that PowerShellGet won't overwrite with the differently-signed newer Pester — add -SkipPublisherCheck there to install side-by-side. Not needed on PowerShell 7+. See https://pester.dev/docs/introduction/installation.

Migration workflow

Run this loop for each major jump. Do not jump two majors at once — go v4→v5, then v5→v6.

  1. Baseline. Run the suite on the current version first and record pass/fail. You need a known-good (or known) starting point so you can tell migration regressions apart from pre-existing failures.
    # Bare Invoke-Pester works on every major; exact parameters differ
    # (v3/v4: -Script/-OutputFile; v5+/v6: -Path/-Output).
    Invoke-Pester
    
  2. Read the reference for this jump (table above) so you know the full scope before editing.
  3. Edit file by file. Apply the mechanical changes (see per-jump cheat sheets below and in the reference). Keep changes small and reviewable — one file or one concern at a time.
  4. Switch versions with Install-Module (Step 0), then re-import: Remove-Module Pester; Import-Module Pester (or start a fresh session).
  5. Run and fix. Re-run with -Output Detailed; use -Output Diagnostic (v4→v5) or read the explicit v6 error messages to locate problems. Match each failure to the symptom → fix tables in the reference.

…

Câu hỏi thường gặp

Pester là gì?

Pester là framework dùng để viết test tự động cho mã PowerShell. Nó giúp kiểm tra xem mã có hoạt động như mong đợi không.

Vì sao tôi cần cập nhật các test Pester?

Giống các phần mềm khác, Pester cũng phát triển. Các phiên bản mới có thể đưa ra thay đổi khiến test viết cho phiên bản cũ không tương thích. Cập nhật giúp test tiếp tục hoạt động và tận dụng tính năng mới.

Tôi có thể bỏ qua một vài phiên bản khi cập nhật không?

Không nên. Tốt nhất nên cập nhật mỗi lần một phiên bản chính (ví dụ từ v3 lên v4, rồi từ v4 lên v5) để quản lý thay đổi hiệu quả hơn và tránh lỗi phức tạp.

Chi tiết

Mô tả gốc của tác giả

Pester migration skill for upgrading PowerShell Pester test suites across major versions — v3→v4, v4→v5, and v5→v6. Covers the Discovery/Run two-phase model, moving setup into BeforeAll, $PSScriptRoot vs $MyInvocation, mock changes (Assert-MockCalled → Should -Invoke, removed fall-through), Invoke-Pester parameters → PesterConfiguration, data-driven -ForEach/-TestCases, and the v6 breaking changes

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7318
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự