PageRenderTime 16ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/core/ThreadedTestRunner.cs

#
C# | 77 lines | 56 code | 12 blank | 9 comment | 4 complexity | 57b4f0aed53c66cbfb4263fb706e5c95 MD5 | raw file
 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.
 5// ****************************************************************
 6namespace NUnit.Core
 7{
 8	using System;
 9	using System.Threading;
10	using System.Collections.Specialized;
11
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
17	{
18        static Logger log = InternalTrace.GetLogger(typeof(ThreadedTestRunner));
19
20		#region Instance Variables
21		private TestRunnerThread testRunnerThread;
22		#endregion
23
24		#region Constructors
25		public ThreadedTestRunner( TestRunner testRunner ) : base ( testRunner ) { }
26		#endregion
27
28		#region Overrides
29		public override TestResult Run( EventListener listener )
30		{
31			BeginRun( listener );
32			return EndRun();
33		}
34
35		public override TestResult Run( EventListener listener, ITestFilter filter )
36		{
37			BeginRun( listener, filter );
38			return EndRun();
39		}
40
41		public override void BeginRun( EventListener listener )
42		{
43            log.Info("BeginRun");
44   			testRunnerThread = new TestRunnerThread( this.TestRunner );
45            testRunnerThread.StartRun( listener );
46		}
47
48		public override void BeginRun( EventListener listener, ITestFilter filter )
49		{
50            log.Info("BeginRun");
51            testRunnerThread = new TestRunnerThread(this.TestRunner);
52			testRunnerThread.StartRun( listener, filter );
53		}
54
55		public override TestResult EndRun()
56		{
57            log.Info("EndRun");
58            this.Wait();
59			return this.TestRunner.TestResult;
60		}
61
62
63		public override void Wait()
64		{
65			if ( testRunnerThread != null )
66				testRunnerThread.Wait();
67		}
68
69		public override void CancelRun()
70		{
71			if ( testRunnerThread != null )
72				testRunnerThread.Cancel();
73		}
74
75		#endregion
76	}
77}