views:

231

answers:

1

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.

+1  A: 

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 ettiqute here. Should I just delete the question or add my answer to the question?

btlog