2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / nunit24 / NUnitCore / core / ThreadedTestRunner.cs
blob45017f1e55027419989424f49b6df98f8e6309a4
1 // ****************************************************************
2 // Copyright 2007, Charlie Poole
3 // This is free software licensed under the NUnit license. You may
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
5 // ****************************************************************
6 namespace NUnit.Core
8 using System;
9 using System.Threading;
10 using System.Collections.Specialized;
12 /// <summary>
13 /// ThreadedTestRunner overrides the Run and BeginRun methods
14 /// so that they are always run on a separate thread. The actual
15 /// </summary>
16 public class ThreadedTestRunner : ProxyTestRunner
18 #region Instance Variables
19 private TestRunnerThread testRunnerThread;
20 #endregion
22 #region Constructors
23 public ThreadedTestRunner( TestRunner testRunner ) : base ( testRunner ) { }
24 #endregion
26 #region Overrides
27 public override TestResult Run( EventListener listener )
29 BeginRun( listener );
30 return EndRun();
33 public override TestResult Run( EventListener listener, ITestFilter filter )
35 BeginRun( listener, filter );
36 return EndRun();
39 public override void BeginRun( EventListener listener )
41 testRunnerThread = new TestRunnerThread( this.TestRunner );
43 testRunnerThread.StartRun( listener );
46 public override void BeginRun( EventListener listener, ITestFilter filter )
48 testRunnerThread = new TestRunnerThread( this.TestRunner );
50 testRunnerThread.StartRun( listener, filter );
53 public override TestResult EndRun()
55 this.Wait();
56 return this.TestRunner.TestResult;
60 public override void Wait()
62 if ( testRunnerThread != null )
63 testRunnerThread.Wait();
66 public override void CancelRun()
68 if ( testRunnerThread != null )
69 testRunnerThread.Cancel();
72 #endregion