Bird
0
0

What will happen when running this Pester test?

medium📝 Command Output Q5 of 15
PowerShell - Scripting Best Practices
What will happen when running this Pester test?
Describe 'String Tests' {
  It 'checks if string is empty' {
    '' | Should -BeNullOrEmpty
  }
}
ATest fails because Should does not support -BeNullOrEmpty
BTest fails because string is not null
CTest passes because string is empty
DTest throws runtime error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the test condition

    The test checks if an empty string is null or empty, which is true.
  2. Step 2: Confirm Pester supports -BeNullOrEmpty

    -BeNullOrEmpty is a valid Pester assertion for strings.
  3. Final Answer:

    Test passes because string is empty -> Option C
  4. Quick Check:

    Empty string check = Test passes [OK]
Quick Trick: Use -BeNullOrEmpty to check empty strings [OK]
Common Mistakes:
  • Confusing empty string with null
  • Thinking -BeNullOrEmpty is unsupported
  • Expecting runtime errors from valid assertions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes