0
0
PowerShellscripting~10 mins

Pester testing framework basics in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a Pester test block.

PowerShell
Describe 'MyFunction' { It 'should return true' { [1] } }
Drag options to blanks, or click blank then click option'
AMyFunction | Should -Be $true
BMyFunction -eq $true
CAssert-True MyFunction
DTest-MyFunction -IsTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using comparison operators like -eq directly without Should.
Trying to call non-existent commands like Assert-True.
2fill in blank
medium

Complete the code to run all Pester tests in the current directory.

PowerShell
Invoke-Pester -[1] .
Drag options to blanks, or click blank then click option'
AScript
BFile
CTest
DPath
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like -File or -Script.
Not specifying any path and expecting tests to run automatically.
3fill in blank
hard

Fix the error in the test assertion to check if a value equals 5.

PowerShell
$result = 5; $result | Should [1] 5
Drag options to blanks, or click blank then click option'
A-Be
B-BeGreaterThan
C-EqualTo
D-Equals
Attempts:
3 left
💡 Hint
Common Mistakes
Using operators like -EqualTo or -Equals which are not valid in Pester.
Using comparison operators like -eq instead of Should -Be.
4fill in blank
hard

Fill both blanks to create a test that checks if a string contains 'hello'.

PowerShell
Describe 'String tests' { It 'contains hello' { 'hello world' | Should [1] [2] } }
Drag options to blanks, or click blank then click option'
A-Match
B-Contain
C'hello'
D'world'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -Contain which is for collections, not strings.
Using the wrong substring or pattern.
5fill in blank
hard

Fill all three blanks to create a test that checks if a list has exactly 3 items.

PowerShell
Describe 'List tests' { It 'has 3 items' { $list = @(1,2,3); $list.[1] | Should [2] [3] } }
Drag options to blanks, or click blank then click option'
ACount
B-Be
C3
DLength
Attempts:
3 left
💡 Hint
Common Mistakes
Using Length instead of Count in PowerShell arrays.
Using wrong assertion operators or values.