mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Update test framework and tests to support 4x version of Pester (#6064)
* Test fixes and changes needed to support Pester 4.0.8 * Replace 'Should Contain' with new 'Should FileContentMatch' assertion Explicitly check for string creation with write-output * Use the current version of pester and install it in modulesDir * Simplify logic for relative path test. Multiple '..' is not needed for a relative path, a single one will do. Also, on multi-drive systems using split-path -noqualifier will probably do the wrong thing with regard to constructing a correct path. Remove extraneous Should Not Throw test, if this throws, the test will fail, we don't need to explicitly assert the not throw * In some environments it is possible that computer name is 'localhost', so that should be allowed * [feature] Add link for migrating tests from Pester v3 to v4 Fix up capitalization and white space issues Change one test to check FullyQualifiedErrorId rather than just `Should Throw` * [feature] update invoke-item test to handle the case where multiple notepad processes are running * Fix spelling issue with Pester 4x, calling it Pester 4 should be sufficient
This commit is contained in:
committed by
Aditya Patwardhan
parent
fa40a87bd7
commit
99a7d38cae
@@ -1,7 +1,11 @@
|
||||
### Writing Pester Tests
|
||||
Note that this document does not replace the documents found in the [Pester](https://github.com/pester/pester "Pester") project. This is just
|
||||
some quick tips and suggestions for creating Pester tests for this project. The Pester community is vibrant and active, if you have questions
|
||||
about Pester or creating tests, the [Pester Wiki](https://github.com/pester/pester/wiki) has a lot of great information.
|
||||
Note that this document does not replace the documents found in the [Pester](https://github.com/pester/pester "Pester") project.
|
||||
This is just some quick tips and suggestions for creating Pester tests for this project.
|
||||
The Pester community is vibrant and active, if you have questions about Pester or creating tests, the [Pester Wiki](https://github.com/pester/pester/wiki) has a lot of great information.
|
||||
As of January 2018, PowerShell Core is using Pester version 4 which has some changes from earlier versions.
|
||||
See [Migrating from Pester 3 to Pester 4](https://github.com/pester/Pester/wiki/Migrating-from-Pester-3-to-Pester-4) for more information.
|
||||
|
||||
|
||||
|
||||
When creating tests, keep the following in mind:
|
||||
* Tests should not be overly complicated and test too many things
|
||||
@@ -16,7 +20,7 @@ Here's the simplest of tests
|
||||
Describe "A variable can be assigned and retrieved" {
|
||||
It "Create a variable and make sure its value is correct" {
|
||||
$a = 1
|
||||
$a | Should be 1
|
||||
$a | Should Be 1
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -27,7 +31,7 @@ If you need to do type checking, that can be done as well
|
||||
Describe "One is really one" {
|
||||
It "Compare 1 to 1" {
|
||||
$a = 1
|
||||
$a | Should be 1
|
||||
$a | Should Be 1
|
||||
}
|
||||
It "1 is really an int" {
|
||||
$i = 1
|
||||
@@ -42,7 +46,7 @@ alternatively, you could do the following:
|
||||
Describe "One is really one" {
|
||||
It "Compare 1 to 1" {
|
||||
$a = 1
|
||||
$a | Should be 1
|
||||
$a | Should Be 1
|
||||
}
|
||||
It "1 is really an int" {
|
||||
$i = 1
|
||||
@@ -136,7 +140,7 @@ $testCases = @(
|
||||
Describe "A test" {
|
||||
It "<a> -xor <b> should be <expectedresult>" -testcase $testcases {
|
||||
param ($a, $b, $ExpectedResult)
|
||||
$a -xor $b | Should be $ExpectedResult
|
||||
$a -xor $b | Should Be $ExpectedResult
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -151,7 +155,7 @@ The following example illustrates simple use:
|
||||
Context "Get-Random is not random" {
|
||||
Mock Get-Random { return 3 }
|
||||
It "Get-Random returns 3" {
|
||||
Get-Random | Should be 3
|
||||
Get-Random | Should Be 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user