public SetUpFixture(Type type) : base(type) { this.TestName.Name = type.Namespace; if (this.TestName.Name == null) { this.TestName.Name = "[default namespace]"; } int index = TestName.Name.LastIndexOf('.'); if (index > 0) { this.TestName.Name = this.TestName.Name.Substring(index + 1); } this.fixtureSetUpMethods = Reflect.GetMethodsWithAttribute(type, NUnitFramework.SetUpAttribute, true); this.fixtureTearDownMethods = Reflect.GetMethodsWithAttribute(type, NUnitFramework.TearDownAttribute, true); #if CLR_2_0 || CLR_4_0 this.actions = ActionsHelper.GetActionsFromTypesAttributes(type); #endif }
/// <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) { SetUpMethods = suite.SetUpMethods; TearDownMethods = suite.TearDownMethods; } } #if CLR_2_0 || CLR_4_0 this.actions = ActionsHelper.GetActionsFromAttributeProvider(this.method); #endif // 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); } Fixture = null; SetUpMethods = null; TearDownMethods = null; #if CLR_2_0 || CLR_4_0 this.actions = null; #endif return(result); }
public NUnitTestFixture(Type fixtureType, object[] arguments) : base(fixtureType, arguments) { var fixtureSetUpMethods = new List <MethodInfo>(); fixtureSetUpMethods.AddRange(Reflect.GetMethodsWithAttribute(fixtureType, NUnitFramework.TestFixtureSetUpAttribute, true)); fixtureSetUpMethods.AddRange(Reflect.GetMethodsWithAttribute(fixtureType, NUnitFramework.OneTimeSetUpAttribute, true)); FixtureSetUpMethods = fixtureSetUpMethods; var fixtureTearDownMethods = new List <MethodInfo>(); fixtureTearDownMethods.AddRange(Reflect.GetMethodsWithAttribute(fixtureType, NUnitFramework.TestFixtureTearDownAttribute, true)); fixtureTearDownMethods.AddRange(Reflect.GetMethodsWithAttribute(fixtureType, NUnitFramework.OneTimeTearDownAttribute, true)); FixtureTearDownMethods = fixtureTearDownMethods; SetUpMethods = Reflect.GetMethodsWithAttribute(this.FixtureType, NUnitFramework.SetUpAttribute, true); TearDownMethods = Reflect.GetMethodsWithAttribute(this.FixtureType, NUnitFramework.TearDownAttribute, true); #if CLR_2_0 || CLR_4_0 this.actions = ActionsHelper.GetActionsFromTypesAttributes(fixtureType); #endif }
/// <summary> /// Initializes a new instance of the <see cref="TestAssembly"/> class. /// </summary> /// <param name="path">The path.</param> public TestAssembly(Assembly assembly, string path) : base(path) { #if CLR_2_0 || CLR_4_0 this.actions = ActionsHelper.GetActionsFromAttributeProvider(assembly); #endif }
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.SetUpMethods; this.tearDownMethods = suite.TearDownMethods; #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(); } }