Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get stdout into mstest output when running in new app domain?

I have been working on test framework, which creates a new app domain to run the tests in. The primary reason being the dll's that we are testing has some horrible code that relies on the dll being located in the app domain path. (No I can't change this code.)

The problem that I am having is that my test team is writing a bunch of functional tests in mstest and one of the loggers, that writes to Console.Out, does not have any of the log information captured in the trx output. When running the code through a console app all of the log information is output fine. So do the other loggers that have been implemented.

My thought is that mstest is setting its own TextWriter to Console.Out, but the new app doamin has it's own TextWriter for Console.Out as the new app domain has it's own set of statics.

I appreciate your ideas.

like image 329
btlog Avatar asked Mar 08 '10 10:03

btlog


1 Answers

I feel a little sheepish, but once I hit send and had a think about it again the problem kinda became obvious and I worked out a solution.

The problem is that the original Console.Out was being set to a new TextWriter by mstest and this wasn't getting set in my new app domain.

So I created a SetConsoleOut method on the class I have created in the new appdomain and I pass it Console.Out.

TestFramework testFramework = 
          (TestFramework)newAppDomain.CreateInstanceAndUnwrap(
                                                "TestFrameworkLibrary",
                                                "MyNamespace.TestFramework");

testFramework.SetConsoleOut(Console.Out);

And in TestFramework I added the method

internal void SetConsoleOut(TextWriter consoleOut)
{
    Console.SetOut(consoleOut);
}

Works like a charm. I am not sure on the etiquette here. Should I just delete the question or add my answer to the question?

like image 168
btlog Avatar answered Oct 03 '22 01:10

btlog