I would like to test a console app, redirecting the std out and std in as described here: Redirecting Console.Out within test Setup and Teardown
This is the code:
private StringWriter _sw;
private StringReader _sr;
[SetUp]
public void SetUp()
{
_sw = new StringWriter();
Console.SetOut(_sw);
_sr = new StringReader("100");
Console.SetIn(_sr);
}
[TearDown]
public void TearDown()
{
var standardOut = new StreamWriter(Console.OpenStandardOutput());
standardOut.AutoFlush = true;
Console.SetOut(standardOut);
Console.SetIn(new StreamReader(Console.OpenStandardInput()));
}
Within each test, I will run code the reads and writes to the console.
As can be seen in the code above, each test will begin with:
_sw = new StringWriter();
Console.SetOut(_sw);
If multiple tests are run in parallel, will these tests conflict with each other?
Isn't it possible that calling Console.SetOut from one test, may change the redirection midway through another test? Wouldn't this disrupt the tests?