Testing output of other streams
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?
You can use PowerShell's redirection operators to dump those streams to files, and then test the content of the files. The details are in about_Redirection, but basically, it's:
Do-Something > $filePath # Redirect output stream
Do-Something 2> $filePath # Redirect error stream
Do-Something 3> $filePath # Redirect warning stream
Do-Something 4> $filePath # Redirect verbose stream
Do-Something 5> $filePath # Redirect debug stream
Do-Something 6> $filePath # Redirect information stream
Keep in mind that in PowerShell v2, you only had the output / error redirection, and the information stream didn't exist until PowerShell v5.
Thanks for the tip, David. I'll pursue the redirection route. Appreciate you including the bit about the information stream, as that part isn't even documented in my version of PowerShell help on about_redirection.