This appears to be fixed in the latest version of the NUnit adapter, 2.1.1.
I was personally fooled, though, by the fact that I was sending a huge amount of output to the Console (which was captured in the Output window, I believe by the adapter) very quickly. This created a sort of "back log" in the output, and .NET wanted to complete sending the output it had received before the test quit. You can simulate this behavior with the following test:
[Test, Timeout(10000)] // Time out in 10 seconds
public void Test_MyFunction_DoesNotRunForever()
{
DateTime start = DateTime.Now;
while (true)
{
TimeSpan runTime = DateTime.Now - start;
System.Diagnostics.Debug.WriteLine("Doing stuff for " + runTime.TotalSeconds + " seconds." + (runTime.TotalSeconds > 10 ? " Buggy! :(" : ""));
}
}
If you watch it run, you'll notice that it's still printing output like Doing stuff for 2.043 seconds. even after minutes have gone by.
If you don't want to reduce the output, you should slow down the output with some well placed artificial slow downs like Thread.Sleep, preferably without changing your code. Even Thread.Sleep(1) is enough to prevent such a backlog. Some options that come to mind:
- If you have mocks, you can put a brief pause in one of your mock's call backs
- Reorganize your code to accept an output sink as an argument, so you can provide a stub that adds a brief pause and then passes the output on.
--trace=Verboseand post the contents of the trace file that is generated? - Patrick Quirk