Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is Pester in PowerShell?
Pester is a testing framework for PowerShell scripts. It helps you write tests to check if your scripts work as expected.
Click to reveal answer
beginner
What is a Describe block in Pester?
A Describe block groups related tests together. Think of it like a chapter title for your tests.
Click to reveal answer
beginner
What does the It block do in Pester?
An It block contains a single test. It describes what the test should check, like a small task or question.
Click to reveal answer
beginner
How do you check if a value equals another in Pester?
Use the Should keyword with the -Be operator. For example: $result | Should -Be 5 checks if $result equals 5.
Click to reveal answer
beginner
How do you run Pester tests in PowerShell?
Run the command Invoke-Pester in the folder with your test files. It runs all tests and shows results.
Click to reveal answer
What keyword starts a group of tests in Pester?
AShould
BIt
CDescribe
DTest
✗ Incorrect
Describe groups related tests together in Pester.
Which block contains a single test in Pester?
AIt
BTest-Case
CShould
DDescribe
✗ Incorrect
It block holds one test case in Pester.
How do you assert that a value equals 10 in Pester?
AAssert-Equal $value 10
B$value | Should -Equal 10
C$value -eq 10
D$value | Should -Be 10
✗ Incorrect
Use Should -Be to check equality in Pester.
Which command runs all Pester tests in the current folder?
ARun-Pester
BInvoke-Pester
CStart-Test
DTest-Invoke
✗ Incorrect
Invoke-Pester runs Pester tests.
What is the main purpose of Pester?
ATo test PowerShell scripts
BTo write PowerShell scripts
CTo deploy PowerShell scripts
DTo debug PowerShell scripts
✗ Incorrect
Pester is used to test PowerShell scripts.
Explain the roles of Describe and It blocks in Pester testing.
Think of Describe as a chapter and It as a paragraph.
You got /3 concepts.
How do you write a simple test in Pester to check if a function returns the number 5?
Start with Describe, then It, then assertion.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the Describe block in a Pester test script?
easy
A. To check if a value matches an expectation
B. To run the tests automatically
C. To define variables for the tests
D. To group related tests together
Solution
Step 1: Understand the role of Describe block
The Describe block is used to group related tests in Pester, making the test script organized and readable.
Step 2: Differentiate from other blocks
It blocks contain individual tests, and Should is used for assertions, not grouping.
Final Answer:
To group related tests together -> Option D
Quick Check:
Describe groups tests = C [OK]
Hint: Describe groups tests; It contains tests; Should checks results [OK]
Common Mistakes:
Confusing Describe with It blocks
Thinking Should groups tests
Assuming Describe runs tests automatically
2. Which of the following is the correct syntax to write a simple test in Pester that checks if the number 5 is greater than 3?
easy
A. Test 'Test' { Check 'checks number' { 5 > 3 ShouldBe True } }
B. Describe 'Test' { It 'checks number' { Should 5 -gt 3 } }
C. Describe 'Test' { It 'checks number' { 5 -gt 3 | Should Be $true } }
D. It 'checks number' { 5 -gt 3 ShouldBe $true }
Solution
Step 1: Identify correct Pester syntax
The correct syntax uses Describe to group, It for the test, and pipes the condition to Should Be $true.
Step 2: Check each option
Describe 'Test' { It 'checks number' { 5 -gt 3 | Should Be $true } } correctly uses Describe, It, and pipes the boolean expression to Should Be $true. Others have syntax errors or wrong keywords.
Final Answer:
Describe 'Test' { It 'checks number' { 5 -gt 3 | Should Be $true } } -> Option C
Quick Check:
Correct syntax uses Describe, It, and Should Be [OK]
Hint: Use Describe and It blocks; pipe condition to Should Be [OK]
Common Mistakes:
Using wrong keywords like Test or Check
Missing pipe before Should
Incorrect comparison operators
3. What will be the output when running this Pester test script?
Describe 'Math Tests' {
It 'checks addition' {
(2 + 2) | Should Be 4
}
It 'checks subtraction' {
(5 - 3) | Should Be 1
}
}
medium
A. One test fails because 5 - 3 is not 1
B. Both tests pass successfully
C. Syntax error due to missing parentheses
D. All tests fail because Should Be is used incorrectly
Solution
Step 1: Evaluate each test condition
The first test checks if 2 + 2 equals 4, which is true. The second test checks if 5 - 3 equals 1, which is false because 5 - 3 equals 2.
Step 2: Determine test results
Since the second test condition is false, that test fails. The first test passes.
4. You wrote this Pester test but it fails to run:
Describe 'Test' {
It 'checks value' {
$result = Get-Value
$result | Should Be 10
}
}
What is the most likely reason for the failure?
medium
A. Get-Value is not a recognized command or function
B. Should Be cannot be used with variables
C. It block must not contain variable assignments
D. Describe block requires a parameter
Solution
Step 1: Analyze the test script
The test calls Get-Value but this command is not standard in PowerShell and likely undefined.
Step 2: Identify cause of failure
Since Get-Value is missing, the script fails before reaching the assertion. Other options are incorrect because variables and Describe blocks are valid as used.
Final Answer:
Get-Value is not a recognized command or function -> Option A
Quick Check:
Undefined commands cause test failures [OK]
Hint: Check if all commands/functions exist before testing [OK]
Common Mistakes:
Assuming Should Be can't use variables
Thinking Describe needs parameters
Believing variable assignment is disallowed in It
5. You want to write a Pester test that checks if a function Get-UserName returns a non-empty string. Which test script correctly achieves this?
hard
A. Describe 'User Tests' { It 'returns non-empty string' { Get-UserName | Should BeNotNullOrEmpty } }
B. Describe 'User Tests' { It 'returns non-empty string' { (Get-UserName) | Should Not BeNullOrEmpty } }
C. Describe 'User Tests' { It 'returns non-empty string' { (Get-UserName) | Should Be $true } }
D. Describe 'User Tests' { It 'returns non-empty string' { Get-UserName | Should Not BeNullOrEmptyString } }
Solution
Step 1: Identify correct assertion for non-empty string
Pester provides Should Not BeNullOrEmpty to check that a value is not null or empty.
Step 2: Check syntax correctness
Describe 'User Tests' { It 'returns non-empty string' { (Get-UserName) | Should Not BeNullOrEmpty } } correctly calls Get-UserName in parentheses and pipes the result to Should Not BeNullOrEmpty. Other options use incorrect assertion names or syntax.
Final Answer:
Describe 'User Tests' { It 'returns non-empty string' { (Get-UserName) | Should Not BeNullOrEmpty } } -> Option B
Quick Check:
Use Should Not BeNullOrEmpty for non-empty string checks [OK]
Hint: Use Should Not BeNullOrEmpty to check non-empty strings [OK]
Common Mistakes:
Using incorrect assertion names like BeNotNullOrEmpty