Author Posts

February 16, 2017 at 5:06 pm

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?

February 16, 2017 at 6:02 pm

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

February 16, 2017 at 8:14 pm

Perfect. This is exactly what I was looking for.

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

February 16, 2017 at 8:27 pm

Glad you found it useful 🙂