Pester: Is it possible to test output of other streams?

Welcome Forums General PowerShell Q&A Pester: Is it possible to test output of other streams?

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
1 year, 10 months ago.

  • Author
    Posts
  • #64440

    Participant
    Points: 1
    Rank: Member

    Looking for ways to test execution flow in my unit tests without asserting anything from the standard output stream. In other words, I'd like to be able to assert things from other output streams, such as the Information stream and the Warning stream. Is this possible?

    Any ideas on how this could be done?

  • #64450

    Participant
    Points: 18
    Rank: Member

    Not sure if this fits your need, but have you looked into stream redirection?

    describe 'Test redirected streams' {
    
        It 'Warning stream should output warning message' {
        
            Write-Warning 'Warning message' 3>&1 | Should Be 'Warning message'
        
        }
    
    }

    Read more about redirection of streams in the Hey, Scripting Guy Understanding Streams, Redirection, and Write-Host in PowerShell by June Blender, and the about_Redirection help topic

    • #64477

      Participant
      Points: 1
      Rank: Member

      Perfect. This is exactly what I was looking for.

      Appreciate you taking the time to respond. Thanks for the additional links as well.

  • #64480

    Participant
    Points: 18
    Rank: Member

    Glad you found it useful 🙂

The topic ‘Pester: Is it possible to test output of other streams?’ is closed to new replies.