protected virtual void CreateUserFixture() { Fixture = Reflect.Construct(FixtureType); }
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; 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(); #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"]); } 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; TestExecutionContext.Restore(); } }