-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLearning_Pester.dib
More file actions
107 lines (67 loc) · 1.97 KB
/
Learning_Pester.dib
File metadata and controls
107 lines (67 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!meta
{"kernelInfo":{"defaultKernelName":"pwsh","items":[{"aliases":[],"languageName":"pwsh","name":"pwsh"}]}}
#!markdown
## Pester Basics
Must be installed to use. Install using:
#!pwsh
Install-Module -Name Pester
#!markdown
### A Pester File
Pester test scripts are just PowerShell files ending in `.Tests.ps1`.
Each Pester file contains one or more `describe` blocks that each contain zero or more `context` blocks that contain one or more `it` blocks that contain assertions.
#!value
describe
|
|-context
|
|-it
|
|-assertions
#!markdown
### `describe` Block
Groups like tests together.
Syntax is a name in 'single quotes' followed by a script block:
#!pwsh
Describe 'IIS' {
}
#!markdown
### `context` Block
The `context` block is optional.
It groups similar `it` blocks together.
#!pwsh
Describe 'IIS' {
Context 'Windows features' {
}
}
#!markdown
### `it` Blocks
Smaller component that labels the actual test to run.
#!pwsh
Describe 'IIS' {
Context 'Windows features' {
It 'installs the Web-Server Windows feature' {
}
}
}
#!markdown
### Assertions
`it` blocks must include one or more assertions.
*Assertions* are the actual test to be ran.
Most common assertion is `Should`, with different operators, such as `-be`, `-bein`, `-belessthan`, etc.
[Full list can be found here.](https://github.com/pester/Pester/wiki/)
#!pwsh
# Note - this will fail bc there is no `Get-WIndowsFeature` command.
Describe 'IIS' {
Context 'Windows features' {
It 'installs the Web-Server Windows feature' {
$parameters = @{
ComputerName = 'WEBSRV1'
Name = 'Web-Server'
}
(Get-WindowsFeature @paarmeters).Installed | Should -Be $true
}
}
}
#!markdown
## Learn More
Learn more about Pester from [The Pester Book](https://leanpub.com/pesterbook/) or from [4sysops articles on Pester](https://4sysops.com/archives/powershell-pester-testing-getting-started/).