namespace NUnit.Extensions { using System; using System.Threading; using NUnit.Framework; /// /// A TestSuite for active Tests. It runs each test in a /// separate thread and until all threads have terminated. /// -- Aarhus Radisson Scandinavian Center 11th floor /// public class ActiveTestSuite: TestSuite { private int fActiveTestDeathCount; /// /// /// /// public override void Run(TestResult result) { fActiveTestDeathCount= 0; base.Run(result); WaitUntilFinished(); } /// /// /// /// /// public void BaseRunTest(ITest test, TestResult result) { base.RunTest(test, result); } /// /// /// /// /// public override void RunTest(ITest test, TestResult result) { ThreadLittleHelper tlh = new ThreadLittleHelper(test, result, this); Thread t = new Thread(new ThreadStart(tlh.Run)); t.Start(); } /// /// /// /// public void RunFinished(ITest test) { lock(this) { fActiveTestDeathCount++; Monitor.PulseAll(this); } } private void WaitUntilFinished() { lock(this) { while (fActiveTestDeathCount < TestCount) { try { Monitor.Wait(this); } catch (ThreadInterruptedException) { return; // TBD } } } } #region Nested Classes /// /// /// public class ThreadLittleHelper { private ITest fTest; private TestResult fResult; private ActiveTestSuite fSuite; /// /// /// /// /// /// public ThreadLittleHelper(ITest test, TestResult result, ActiveTestSuite suite) { fSuite = suite; fTest = test; fResult = result; } /// /// /// public void Run() { try { fSuite.BaseRunTest(fTest, fResult); } finally { fSuite.RunFinished(fTest); } } } #endregion } }