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

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by  Christian Sandfeld 7 months, 1 week ago.

  • Author
    Posts
  • #64440

    Greg Tate
    Participant

    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

    Christian Sandfeld
    Participant

    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

      Greg Tate
      Participant

      Perfect. This is exactly what I was looking for.

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

  • #64480

    Christian Sandfeld
    Participant

    Glad you found it useful 🙂

You must be logged in to reply to this topic.