/// <summary> /// Override Run, setting Fixture to that of the Parent. /// </summary> /// <param name="listener"></param> /// <param name="filter"></param> /// <returns></returns> public override TestResult Run(EventListener listener, ITestFilter filter) { if (this.Parent != null) { this.Fixture = this.Parent.Fixture; TestSuite suite = this.Parent as TestSuite; if (suite != null) { this.setUpMethods = suite.GetSetUpMethods(); this.tearDownMethods = suite.GetTearDownMethods(); } } // DYNAMIC: Get the parameters, and add the methods here. TestResult result = base.Run(listener, filter); if (this.isTheory && result.ResultState == ResultState.Inconclusive) { result.SetResult( ResultState.Failure, this.TestCount == 0 ? "No test cases were provided" : "All test cases were inconclusive", null); } this.Fixture = null; this.setUpMethods = null; this.tearDownMethods = null; return(result); }
private TestResult RunTestInContext() { TestExecutionContext.Save(); TestExecutionContext.CurrentContext.CurrentTest = this; ContextDictionary context = Context; context._ec = TestExecutionContext.CurrentContext; CallContext.SetData("NUnit.Framework.TestContext", context); if (this.Parent != null) { this.Fixture = this.Parent.Fixture; TestSuite suite = this.Parent as TestSuite; if (suite != null) { this.setUpMethods = suite.GetSetUpMethods(); this.tearDownMethods = suite.GetTearDownMethods(); } } try { // Temporary... to allow for tests that directly execute a test case if (Fixture == null && !method.IsStatic) Fixture = Reflect.Construct(this.FixtureType); if (this.Properties["_SETCULTURE"] != null) TestExecutionContext.CurrentContext.CurrentCulture = new System.Globalization.CultureInfo((string)Properties["_SETCULTURE"]); if (this.Properties["_SETUICULTURE"] != null) TestExecutionContext.CurrentContext.CurrentUICulture = new System.Globalization.CultureInfo((string)Properties["_SETUICULTURE"]); return RunRepeatedTest(); } catch (Exception ex) { log.Debug("TestMethod: Caught " + ex.GetType().Name); if (ex is ThreadAbortException) Thread.ResetAbort(); TestResult testResult = new TestResult(this); RecordException(ex, testResult, FailureSite.Test); return testResult; } finally { Fixture = null; CallContext.FreeNamedDataSlot("NUnit.Framework.TestContext"); TestExecutionContext.Restore(); } }
/// <summary> /// Override Run, setting Fixture to that of the Parent. /// </summary> /// <param name="listener"></param> /// <param name="filter"></param> /// <returns></returns> public override TestResult Run(EventListener listener, ITestFilter filter) { if (this.Parent != null) { this.Fixture = this.Parent.Fixture; TestSuite suite = this.Parent as TestSuite; if (suite != null) { this.setUpMethods = suite.GetSetUpMethods(); this.tearDownMethods = suite.GetTearDownMethods(); } } // DYNAMIC: Get the parameters, and add the methods here. return(base.Run(listener, filter)); }
public virtual void Run(TestResult testResult) { try { if (this.Parent != null) { this.Fixture = this.Parent.Fixture; TestSuite suite = this.Parent as TestSuite; if (suite != null) { this.setUpMethods = suite.GetSetUpMethods(); this.tearDownMethods = suite.GetTearDownMethods(); } } // Temporary... to allow for tests that directly execute a test case if (Fixture == null && !method.IsStatic) { Fixture = Reflect.Construct(this.FixtureType); } if (this.Properties["_SETCULTURE"] != null) { TestContext.CurrentCulture = new System.Globalization.CultureInfo((string)Properties["_SETCULTURE"]); } if (this.Properties["_SETUICULTURE"] != null) { TestContext.CurrentUICulture = new System.Globalization.CultureInfo((string)Properties["_SETUICULTURE"]); } int repeatCount = this.Properties.Contains("Repeat") ? (int)this.Properties["Repeat"] : 1; while (repeatCount-- > 0) { if (RequiresThread || Timeout > 0 || ApartmentState != GetCurrentApartment()) { new TestMethodThread(this).Run(testResult, NullListener.NULL, TestFilter.Empty); } else { doRun(testResult); } if (testResult.ResultState == ResultState.Failure || testResult.ResultState == ResultState.Error || testResult.ResultState == ResultState.Cancelled) { break; } } } catch (Exception ex) { if (ex is ThreadAbortException) { Thread.ResetAbort(); } RecordException(ex, testResult, FailureSite.Test); } finally { Fixture = null; } }
private TestResult RunTestInContext() { TestExecutionContext.Save(); TestExecutionContext.CurrentContext.CurrentTest = this; if (this.Parent != null) { this.Fixture = this.Parent.Fixture; TestSuite suite = this.Parent as TestSuite; if (suite != null) { this.setUpMethods = suite.GetSetUpMethods(); this.tearDownMethods = suite.GetTearDownMethods(); #if CLR_2_0 || CLR_4_0 this.suiteActions = suite.GetTestActions(); #endif } } try { #if CLR_2_0 || CLR_4_0 this.actions = ActionsHelper.GetActionsFromAttributeProvider(method); #endif // Temporary... to allow for tests that directly execute a test case); if (Fixture == null && !method.IsStatic) { Fixture = Reflect.Construct(this.FixtureType); } if (this.Properties["_SETCULTURE"] != null) { TestExecutionContext.CurrentContext.CurrentCulture = new System.Globalization.CultureInfo((string)Properties["_SETCULTURE"]); } else if (this.Properties["SetCulture"] != null) // In case we are running NUnitLite tests { TestExecutionContext.CurrentContext.CurrentCulture = new System.Globalization.CultureInfo((string)Properties["SetCulture"]); } if (this.Properties["_SETUICULTURE"] != null) { TestExecutionContext.CurrentContext.CurrentUICulture = new System.Globalization.CultureInfo((string)Properties["_SETUICULTURE"]); } if (this.Properties["SetUICulture"] != null) // In case we are running NUnitLite tests { TestExecutionContext.CurrentContext.CurrentUICulture = new System.Globalization.CultureInfo((string)Properties["SetUICulture"]); } return(RunRepeatedTest()); } catch (Exception ex) { log.Debug("TestMethod: Caught " + ex.GetType().Name); if (ex is ThreadAbortException) { Thread.ResetAbort(); } TestResult testResult = new TestResult(this); RecordException(ex, testResult, FailureSite.Test); return(testResult); } finally { Fixture = null; TestExecutionContext.Restore(); } }