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 - needed?
49 private TestResult[] results;
55 public TestRunnerThread( TestRunner runner )
58 this.thread = new Thread( new ThreadStart( TestRunnerThreadProc ) );
60 this.settings = (NameValueCollection)
61 ConfigurationSettings.GetConfig( "NUnit/TestRunner" );
65 string apartment = (string)settings["ApartmentState"];
66 if ( apartment == "STA" )
67 thread.ApartmentState = ApartmentState.STA;
68 else if ( apartment == "MTA" )
69 thread.ApartmentState = ApartmentState.MTA;
71 string priority = (string)settings["ThreadPriority"];
72 if ( priority != null )
73 thread.Priority = (ThreadPriority)
74 System.Enum.Parse( typeof( ThreadPriority ), priority, true );
78 // Ignore any problems for now - test will run using default settings
84 #region Public Methods
88 if ( this.thread.IsAlive )
98 public void Run( EventListener listener )
100 this.listener = listener;
104 public void Run( EventListener listener, string testName )
106 this.listener = listener;
107 this.testNames = new string[] { testName };
111 public void Run( EventListener listener, string[] testNames )
113 this.listener = listener;
114 this.testNames = testNames;
124 /// The thread proc for our actual test run
126 private void TestRunnerThreadProc()
130 //TODO: do we need a run started event?
131 int count = runner.CountTestCases( testNames );
133 Directory.SetCurrentDirectory( AppDomain.CurrentDomain.BaseDirectory );
134 results = runner.Run(listener, testNames );
136 //TODO: do we need a run finished event?
138 catch( Exception exception )
140 lastException = exception;
141 //TODO: do we need a run finished event?
145 testNames = null; // Do we need this?
146 //runningThread = null; // Ditto