diff options
author | Nick Drochak <nickd@mono-cvs.ximian.com> | 2002-01-19 22:55:23 +0300 |
---|---|---|
committer | Nick Drochak <nickd@mono-cvs.ximian.com> | 2002-01-19 22:55:23 +0300 |
commit | b3a9502b960559d7a6b6c9712be8dd052b2e0e19 (patch) | |
tree | da34a2b334adf9a39aacdd9432552db1bdd39999 /mcs/nunit/src/NUnitCore/ActiveTestSuite.cs | |
parent | aa634bb0419989a60379efba25e04e149936158e (diff) |
* Added sources and makefile for NUnit
svn path=/trunk/mcs/; revision=2066
Diffstat (limited to 'mcs/nunit/src/NUnitCore/ActiveTestSuite.cs')
-rw-r--r-- | mcs/nunit/src/NUnitCore/ActiveTestSuite.cs | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/mcs/nunit/src/NUnitCore/ActiveTestSuite.cs b/mcs/nunit/src/NUnitCore/ActiveTestSuite.cs new file mode 100644 index 00000000000..605911d233c --- /dev/null +++ b/mcs/nunit/src/NUnitCore/ActiveTestSuite.cs @@ -0,0 +1,93 @@ +namespace NUnit.Extensions {
+
+ using System;
+ using System.Threading;
+
+ using NUnit.Framework;
+
+ /// <summary>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</summary>
+ public class ActiveTestSuite: TestSuite {
+ private int fActiveTestDeathCount;
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="result"></param>
+ public override void Run(TestResult result) {
+ fActiveTestDeathCount= 0;
+ base.Run(result);
+ WaitUntilFinished();
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ public class ThreadLittleHelper {
+ private ITest fTest;
+ private TestResult fResult;
+ private ActiveTestSuite fSuite;
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ /// <param name="result"></param>
+ /// <param name="suite"></param>
+ public ThreadLittleHelper(ITest test, TestResult result,
+ ActiveTestSuite suite) {
+ fSuite = suite;
+ fTest = test;
+ fResult = result;
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ public void Run() {
+ try {
+ fSuite.BaseRunTest(fTest, fResult);
+ } finally {
+ fSuite.RunFinished(fTest);
+ }
+ }
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ /// <param name="result"></param>
+ public void BaseRunTest(ITest test, TestResult result) {
+ base.RunTest(test, result);
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ /// <param name="result"></param>
+ 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();
+ }
+ void WaitUntilFinished() {
+ lock(this) {
+ while (fActiveTestDeathCount < TestCount) {
+ try {
+ Monitor.Wait(this);
+ } catch (ThreadInterruptedException) {
+ return; // TBD
+ }
+ }
+ }
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ public void RunFinished(ITest test) {
+ lock(this) {
+ fActiveTestDeathCount++;
+ Monitor.PulseAll(this);
+ }
+ }
+ }
+}
|