[Mono-list] NUnit does not detect Fail() in other threads?

a b11112 ab11112@hotmail.com
Tue, 29 Oct 2002 12:34:52 +0100


Is it just me or does NUnit fail to
detect assertion failures in other
threads? Running the below test,
NUnit reports no errors. I think
it's not a problem with the test
itself, but correct me if it is.

This behavior would agree with what
I understand from the NUnit sources:
an assertion is handled as an exception
and caught at the top, so from other threads
the exception disappears "ins Blaue hinein".

This was reported about a month ago
(bug 618502), but no reaction yet.
Could require major changes to NUnit's
internals.
As far as I can tell from the API docs,
there is no way to catch that exception
when the child exits. Suggested workaround
is to put e.g. "thread_reached_end = true"
just before the child's regular return
statement and assert that in the parent
after Join().

--------------------

using NUnit.Framework;
using System;
using System.Threading;

namespace MyTests.Foobar
{

[TestFixture]
public class FoobarTest
{
	private static bool thread_entered;

	private static void otherthread()
	{
		thread_entered = true;
		Assertion.Fail("This should fail, but does not.");
	}

	[Test]
	public void Test1()
	{
		Thread t;
		ThreadStart ts;

		thread_entered = false;
		ts = new ThreadStart(otherthread);
		t = new Thread(ts);
		t.Start();
		t.Join();
		Assertion.AssertEquals("thread should have been entered", thread_entered, 
true);
	}
}
}


_________________________________________________________________
Je kan ook Messenger berichten op je mobiele telefoon ontvangen! 
http://www.msn.nl/services/hotmailsmsv271551/messenger/