jcansdale / TestDriven.Net-Issues

Issue tracking for TestDriven.Net
https://github.com/jcansdale/TestDriven.Net-Issues/issues
24 stars 2 forks source link

Ad-hoc Test Runner: Debug.WriteLine in .NET 5/Core doesn't write to Output window #156

Open duncansmart opened 3 years ago

duncansmart commented 3 years ago

Using the ad-hoc test runner in .NET 4.x and earlier, doing a Debug.WriteLine outputs the messages to the Output window. In .NET 5 (and Core) this isn't the case. A workaround is to add Trace.Listeners.Add(new ConsoleTraceListener()) to my code somewhere every time I write an ad-hoc test, but this is a bit of a faff.

🙏 Could a console TraceListener be added to Trace.Listeners in TestDriven.NetCore.AdHoc.dll instead of me having to do it manually each time?

I've decompiled TestDriven.NetCore.AdHoc.dll and added the following code to Program.Main and replaced it:

public static int Main(string[] args)
{
    Trace.Listeners.Add(new ConsoleTraceListener());
    ...
}

class ConsoleTraceListener : TraceListener
{
    public override void Write(string message) => Console.Write(message);
    public override void WriteLine(string message) => Console.WriteLine(message);
}

And it now works as it does under .NET 4.x