Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using comparison operators like -eq directly without Should.
Trying to call non-existent commands like Assert-True.
✗ Incorrect
The Should command is used inside It blocks to assert expected results in Pester.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like -File or -Script.
Not specifying any path and expecting tests to run automatically.
✗ Incorrect
The -Path parameter tells Invoke-Pester where to find test files.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The correct Pester assertion to check equality is -Be.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -Contain which is for collections, not strings.
Using the wrong substring or pattern.
✗ Incorrect
Use -Match to check if a string matches a pattern, and the pattern here is 'hello'.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Length instead of Count in PowerShell arrays.
Using wrong assertion operators or values.
✗ Incorrect
Use Count property to get number of items, then Should -Be 3 to assert the count.