Migrating from Pester v3 to v4
Migration from Pester 3 to 4 typically involves minor changes to test code. Sometimes the migration requires no changes at all. This guide is meant to help you understand and make the necessary changes to your existing test code to accommodate Pester 4.
Update to New Names
We recommend performing string replacement on tests written for Pester 3 and earlier as follows:
- replace all occurrences of any
Contain
assertion withFileContentMatch
. - rename all occurrences of
Assert-VerifiableMocks
toAssert-VerifiableMock
You can use this simple script that can migrate test files in UTF8 and ASCII encoding.
⚠️ Please verify manually results generated by the script - it can generate false positive replaces!
Update to the new assertions syntax
In Pester 4.0 the new assertion syntax was introduced. \ Now assertions can be provided as parameters to Should, that allows richer assertion vocabulary.
Old syntax
New syntax
For most cases tests can be updated using the function provided below.
⚠️ Please verify manually results generated by the script specially if your scripts are not UTF-8 or ASCII encoded!
Mock-Related Changes
We are not 100% sure what implications changing from functions to aliases had on mocking. There are no immediate changes that you need to do, but here are two articles that should help you start figuring out issues if you have any:
Array-Related Changes
The Should
command now performs array assertions. For the most part this change is transparent to existing tests. There are some edge cases, however, where a test involving an array passes in Pester 3 but fails in Pester 4. This article contains such an example.
Related (Github) Issues
Visit this link for all Migration Related Issues.