I am building a unit test in C# with NUnit, and I’d like to test that the main program actually outputs the right output depending on the command line arguments.
Is there a way from an NUnit test method that calls Program.Main(...) to grab everything written to Console.Out and Console.Error so that I can verify against it?
You can redirect
Console.In,Console.OutandConsole.Errorto custom StringWriters, like thisSee this blog post for full details.