public void Halt() { if (_currentTest != null) { _currentTest.Halt(); } else { _delayedHalt = true; } }
/// <summary> /// Stops tests execution immediately, or stops test dispatcher. /// </summary> /// <remarks>There sill can be some delay between pressing "Halt" and real stop, but all /// potentially long actions - waiting for DUT answer or pause between tests - are /// interrupted immediately.</remarks> public void Halt() { _stop = true; if (_currentTest != null) { System.Diagnostics.Debug.WriteLine("Halt - stop running test"); _currentTest.Halt(); } else { System.Diagnostics.Debug.WriteLine("Halt - no test is running"); _haltEvent.Set(); lock (_pauseSync) { _delayedHalt = true; } } }
void RunTests() { Type[] types = new Type[] { typeof(string) }; object[] args = new object[] { _parameters.Address }; foreach (MethodInfo mi in _parameters.TestCases) { if (_stop) { break; } try { _currentTest = null; Type t = mi.DeclaringType; System.Reflection.ConstructorInfo ci = t.GetConstructor( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, System.Reflection.CallingConventions.HasThis, types, null); object itObject = ci.Invoke(args); // todo: check if t is descendant of ITestSuite BaseTest test = (BaseTest)itObject; test.OnStepCompleted += new StepCompleted(test_OnStepCompleted); test.OnTestCompleted += new TestCompleted(test_OnTestCompleted); _currentTest = itObject as TestSuite; //System.Diagnostics.Debug.WriteLine(string.Format("{0}, Sleep 10 seconds before running test", System.DateTime.Now.ToString("HH:mm:ss ffffff"))); //Thread.Sleep(10000); //System.Diagnostics.Debug.WriteLine(string.Format("{0}, Run test", System.DateTime.Now.ToString("HH:mm:ss ffffff"))); if (_delayedPause) { _currentTest.Pause(); } if (_delayedHalt) { _currentTest.Halt(); } mi.Invoke(itObject, new object[0]); } catch (System.Reflection.TargetException exc) { _currentTest.ReportMethodInvocationException(mi, exc); ReportException(exc); } catch (System.ArgumentException exc) { _currentTest.ReportMethodInvocationException(mi, exc); ReportException(exc); } //catch (System.Reflection.TargetInvocationException exc) //{ // _testSuite.ReportMethodInvocationException(mi, exc); // ReportException(exc); //} catch (System.Reflection.TargetParameterCountException exc) { _currentTest.ReportMethodInvocationException(mi, exc); ReportException(exc); } catch (System.MethodAccessException exc) { _currentTest.ReportMethodInvocationException(mi, exc); ReportException(exc); } catch (System.InvalidOperationException exc) { _currentTest.ReportMethodInvocationException(mi, exc); ReportException(exc); } catch (Exception exc) { // // TestFailed currently does not throw any exceptions // // ToDo : ??? // possibly, write some info in log ? But TestRunner knows nothing about log // and may be it's OK that all logs are done in corresponding methods... // // ... so, may be all exceptions are from Invoke(...) ? ReportException(exc); } } if (OnTestSuiteCompleted != null) { OnTestSuiteCompleted(); } }