Challenge - 5 Problems
Pester Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Pester test block?
Consider this Pester test script:
What will Pester report after running this script?
Describe 'Math tests' {
It 'adds numbers correctly' {
(2 + 3) | Should -Be 5
}
It 'multiplies numbers correctly' {
(4 * 2) | Should -Be 8
}
}What will Pester report after running this script?
PowerShell
Describe 'Math tests' { It 'adds numbers correctly' { (2 + 3) | Should -Be 5 } It 'multiplies numbers correctly' { (4 * 2) | Should -Be 8 } }
Attempts:
2 left
💡 Hint
Both math operations are correct, so both tests should pass.
✗ Incorrect
The script defines two tests, both with correct assertions. Pester will report 2 tests run, both passed.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this Pester test
Look at this Pester test code:
Which option correctly describes the syntax error?
Describe 'String tests' {
It 'checks string length' {
'hello'.Length | Should -Be 5
}
It 'checks string content'
'hello' | Should -Be 'hello'
}Which option correctly describes the syntax error?
PowerShell
Describe 'String tests' { It 'checks string length' { 'hello'.Length | Should -Be 5 } It 'checks string content' 'hello' | Should -Be 'hello' }
Attempts:
2 left
💡 Hint
Each It block must have braces enclosing its code.
✗ Incorrect
The second It block lacks the opening brace '{', causing a syntax error.
🔧 Debug
advanced2:00remaining
Why does this Pester test fail unexpectedly?
Given this Pester test:
Why does the second test fail?
$value = 10
Describe 'Value tests' {
It 'checks if value is greater than 5' {
$value -gt 5 | Should -Be $true
}
It 'checks if value is less than 20' {
$value -lt 20 | Should -Be $false
}
}Why does the second test fail?
PowerShell
$value = 10 Describe 'Value tests' { It 'checks if value is greater than 5' { $value -gt 5 | Should -Be $true } It 'checks if value is less than 20' { $value -lt 20 | Should -Be $false } }
Attempts:
2 left
💡 Hint
Check the logic of the condition and the expected value in the second test.
✗ Incorrect
The condition '$value -lt 20' is true because 10 is less than 20, but the test expects $false, so it fails.
🚀 Application
advanced2:00remaining
How to test a function output with Pester?
You have this PowerShell function:
Which Pester test block correctly verifies that calling Get-Greeting with 'Alice' returns 'Hello, Alice!'?
function Get-Greeting {
param([string]$Name)
"Hello, $Name!"
}Which Pester test block correctly verifies that calling Get-Greeting with 'Alice' returns 'Hello, Alice!'?
PowerShell
function Get-Greeting { param([string]$Name) "Hello, $Name!" } Describe 'Get-Greeting function' { It 'returns correct greeting for Alice' { # Fill in the test here } }
Attempts:
2 left
💡 Hint
Use the function call on the left side of the Should command and the expected string on the right.
✗ Incorrect
Option A correctly calls the function with named parameter and compares output to expected string.
🧠 Conceptual
expert2:00remaining
What is the purpose of the 'BeforeAll' block in Pester?
In Pester testing, what does the 'BeforeAll' block do compared to 'BeforeEach'?
Attempts:
2 left
💡 Hint
Think about setup code that should run once versus before every test.
✗ Incorrect
'BeforeAll' is used to run setup code once before any tests run in the Describe block. 'BeforeEach' runs before each individual test.