3 using System.Threading;
4 using System.Configuration;
5 using System.Collections.Specialized;
10 /// Summary description for TestRunnerThread.
12 public class TestRunnerThread
14 #region Private Fields
17 /// The Test runner to be used in running tests on the thread
19 private TestRunner runner;
22 /// The System.Threading.Thread created by the object
24 private Thread thread;
27 /// Collection of TestRunner settings from the config file
29 private NameValueCollection settings;
32 /// The exception that terminated a test run
34 private Exception lastException;
37 /// The EventListener interface to receive test events
39 private NUnit.Core.EventListener listener;
42 /// Array of test names for ues by the thread proc
44 private string[] testNames;
47 /// Array of returned results
49 private TestResult[] results;
56 /// Array of returned results
58 public TestResult[] Results
60 get { return results; }
67 public TestRunnerThread( TestRunner runner )
70 this.thread = new Thread( new ThreadStart( TestRunnerThreadProc ) );
72 this.settings = (NameValueCollection)
73 ConfigurationSettings.GetConfig( "NUnit/TestRunner" );
77 string apartment = (string)settings["ApartmentState"];
78 if ( apartment == "STA" )
79 thread.ApartmentState = ApartmentState.STA;
80 else if ( apartment == "MTA" )
81 thread.ApartmentState = ApartmentState.MTA;
83 string priority = (string)settings["ThreadPriority"];
84 if ( priority != null )
85 thread.Priority = (ThreadPriority)
86 System.Enum.Parse( typeof( ThreadPriority ), priority, true );
90 // Ignore any problems for now - test will run using default settings
96 #region Public Methods
100 if ( this.thread.IsAlive )
110 public void Run( EventListener listener )
112 this.listener = listener;
116 public void Run( EventListener listener, string testName )
118 this.listener = listener;
119 this.testNames = new string[] { testName };
123 public void Run( EventListener listener, string[] testNames )
125 this.listener = listener;
126 this.testNames = testNames;
136 /// The thread proc for our actual test run
138 private void TestRunnerThreadProc()
142 //TODO: do we need a run started event?
144 results = runner.Run(listener, testNames );
146 //TODO: do we need a run finished event?
148 catch( Exception exception )
150 lastException = exception;
151 //TODO: do we need a run finished event?
155 testNames = null; // Do we need this?
156 //runningThread = null; // Ditto