public static TestSuiteResult RunChildCommands(TestSuiteCommand command, TestExecutionContext context) { TestSuiteResult suiteResult = TestExecutionContext.CurrentContext.CurrentResult as TestSuiteResult; suiteResult.SetResult(ResultState.Success); foreach (TestCommand childCommand in command.Children) { TestResult childResult = CommandRunner.Execute(childCommand); suiteResult.AddResult(childResult); if (childResult.ResultState == ResultState.Cancelled) { break; } if (childResult.ResultState.Status == TestStatus.Failed && TestExecutionContext.CurrentContext.StopOnError) { break; } } return(suiteResult); }
public void RunFailed(string failureMessage) { var nunitTestResult = new TestSuiteResult(new TestSuite("test")); nunitTestResult.SetResult(ResultState.Error, failureMessage); var testResult = m_AdaptorFactory.Create(nunitTestResult); TryInvokeAllCallbacks(callbacks => callbacks.RunFinished(testResult)); }
/// <summary> /// Does the one time tear down for a suite command. /// </summary> /// <param name="context">The execution context to use in running the test.</param> public virtual void DoOneTimeTearDown(TestExecutionContext context) { if (fixtureType != null) { TestSuiteResult suiteResult = context.CurrentResult as TestSuiteResult; try { if (suite.OneTimeTearDownMethods != null) { int index = suite.OneTimeTearDownMethods.Length; while (--index >= 0) { MethodInfo fixtureTearDown = suite.OneTimeTearDownMethods[index]; Reflect.InvokeMethod(fixtureTearDown, fixtureTearDown.IsStatic ? null : context.TestObject); } } IDisposable disposable = context.TestObject as IDisposable; if (disposable != null) { disposable.Dispose(); } } catch (Exception ex) { // Error in TestFixtureTearDown or Dispose causes the // suite to be marked as a error, even if // all the contained tests passed. NUnitException nex = ex as NUnitException; if (nex != null) { ex = nex.InnerException; } // TODO: Can we move this logic into TestResult itself? string message = "TearDown : " + ExceptionHelper.BuildMessage(ex); if (suiteResult.Message != null) { message = suiteResult.Message + NUnit.Env.NewLine + message; } #if !NETCF_1_0 string stackTrace = "--TearDown" + NUnit.Env.NewLine + ExceptionHelper.BuildStackTrace(ex); if (suiteResult.StackTrace != null) { stackTrace = suiteResult.StackTrace + NUnit.Env.NewLine + stackTrace; } // TODO: What about ignore exceptions in teardown? suiteResult.SetResult(ResultState.Error, message, stackTrace); #else Result.SetResult(ResultState.Error, message); #endif } } }
public void SuiteFinished(string labelsOption, TestStatus resultStatus, string resultLabel, string output, string expected) { var result = new TestSuiteResult(new TestSuite("DummySuite")); result.SetResult(new ResultState(resultStatus, resultLabel)); foreach (var line in output.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) { result.OutWriter.WriteLine(line); } CreateTextUI(labelsOption).TestFinished(result); Assert.That(Report, Is.EqualTo(expected)); }
public virtual void DoOneTimeTearDown(TestExecutionContext context) { if (fixtureType == null) { return; } TestSuiteResult testSuiteResult = context.CurrentResult as TestSuiteResult; try { if (suite.OneTimeTearDownMethods != null) { int num = suite.OneTimeTearDownMethods.Length; while (--num >= 0) { MethodInfo methodInfo = suite.OneTimeTearDownMethods[num]; Reflect.InvokeMethod(methodInfo, methodInfo.IsStatic ? null : context.TestObject); } } (context.TestObject as IDisposable)?.Dispose(); } catch (Exception innerException) { NUnitException ex = innerException as NUnitException; if (ex != null) { innerException = ex.InnerException; } string text = "TearDown : " + ExceptionHelper.BuildMessage(innerException); if (testSuiteResult.Message != null) { text = testSuiteResult.Message + Env.NewLine + text; } string text2 = "--TearDown" + Env.NewLine + ExceptionHelper.BuildStackTrace(innerException); if (testSuiteResult.StackTrace != null) { text2 = testSuiteResult.StackTrace + Env.NewLine + text2; } testSuiteResult.SetResult(ResultState.Error, text, text2); } }