-
Notifications
You must be signed in to change notification settings - Fork 759
Description
Hi,
We switched from NUnit 2 to NUnit 3, but we have some issues with displaying logs from background thread in the console.
We have a dynamic library (written in C++, for which we created a CLI wrapper to be able to use it in C# projects) that we are testing with NUnit app. This library provides a logger object on the interface that can be used to display the logs from it, so we are using log4net to display the library logs to the console (using a custom ConsoleAppender) and to a file (using RollingFileAppender).
We are using a custom log4net console appender in order to display the library log lines in real time in the console using the TestContext.Progress.Write() method as mentioned here #1139 (this is needed because NUnit 3 is displaying the console output only when the test is finished and this is not acceptable for us):
public class NUnit3ConsoleAppender : log4net.Appender.ConsoleAppender
{
override protected void Append(log4net.Core.LoggingEvent loggingEvent)
{
TestContext.Progress.Write(RenderLoggingEvent(loggingEvent));
}
}
In the app.config file we have:
<appender name="NUnit3ConsoleAppender" type="MyNamespace.NUnit3ConsoleAppender, MyNamespace">
...
<root>
<level value="ALL" />
<appender-ref ref="NUnit3ConsoleAppender" />
</root>
The main problem is that the library log lines from a background thread are not displayed in the console, only the library log lines from the main thread are displayed in the console. We have this issue when executing the tests with 'NUnit Console 3.15' and also with 'TestCentric 2.0.0-alpha6'.
Interesting is that the library log lines from the background thread correctly appear in the file where we are saving the output using log4net, they are only missing in the console.
Even if we don't use a custom log4net console appender but use the existing log4net console appender (appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender") which displayed the logs to the console after the NUnit test has finished, the library log lines from the background thread are still missing from the console.
With NUnit 2 (v2.6.4) we don't have this issue, only with NUnit 3.
We saw that NUnit 3 provides support for parallel test execution and that's why NUnit 3 is capturing the output and then prints it to the console when the test finishes running. That way, the output is matched with the test, not interleaved with other tests.
We do not want to execute the tests in parallel, so we tried adding [NonParallelizable] to the NUnit test and also [SingleThreadedAttribute] to the TestFixture, but it didn't help.
Is there a way to correctly display the library log lines from background thread in the console when using NUnit 3?
Thank you,
Peter