private void FindMethods(Type t, TestCollection tc) { // now get all the methods on the fixture MethodInfo[] methods = t.GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); // if there is a fixture setup routine, invoke it foreach (MethodInfo mi in methods) { if (mi.IsPrivate) continue; object[] attr = mi.GetCustomAttributes(true); foreach (Attribute a in attr) { if (a is TestFixtureSetUpAttribute) tc.classSetup = mi; else if (a is TestFixtureTearDownAttribute) tc.classTeardown = mi; else if (a is SetUpAttribute) tc.setup = mi; else if (a is TearDownAttribute) tc.tearDown = mi; else if (a is TestAttribute) { TestMethod tm = new TestMethod(); tm.member = mi; tc.testMethods.Add(tm); } } } }
public void EndFixture(TestCollection tc) { try { if (tc.classTeardown != null) { tc.classTeardown.Invoke(tc.fixture, null); } } catch (Exception ex) { tc.message = ex.Message; tc.stack = ex.StackTrace; throw; } }
private void FindMethods(Type t, TestCollection tc) { // now get all the methods on the fixture MethodInfo[] methods = t.GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); // if there is a fixture setup routine, invoke it foreach (MethodInfo mi in methods) { if (mi.IsPrivate) { continue; } object[] attr = mi.GetCustomAttributes(true); foreach (Attribute a in attr) { if (a is TestFixtureSetUpAttribute) { tc.classSetup = mi; } else if (a is TestFixtureTearDownAttribute) { tc.classTeardown = mi; } else if (a is SetUpAttribute) { tc.setup = mi; } else if (a is TearDownAttribute) { tc.tearDown = mi; } else if (a is TestAttribute) { TestMethod tm = new TestMethod(); tm.member = mi; tc.testMethods.Add(tm); } } } }
public void StartFixture(TestCollection tc) { try { if (tc.fixture == null) { tc.fixture = Activator.CreateInstance(tc.fixtureType); } if (tc.classSetup != null) { tc.classSetup.Invoke(tc.fixture, null); } } catch (Exception ex) { tc.message = ex.Message; tc.stack = ex.StackTrace; throw; } }
public ArrayList LoadTests() { Assembly me = Assembly.GetExecutingAssembly(); Type[] types = me.GetTypes(); foreach (Type t in types) { object[] o = t.GetCustomAttributes(typeof(TestFixtureAttribute), false); if (o == null || o.Length == 0) continue; TestCollection tc = new TestCollection(); tc.name = t.Name; tc.fixtureType = t; FindMethods(t, tc); if (tc.testMethods.Count > 0) tests.Add(tc); } return tests; }
public void StartFixture(TestCollection tc) { try { if (tc.fixture == null) tc.fixture = Activator.CreateInstance(tc.fixtureType); if (tc.classSetup != null) tc.classSetup.Invoke(tc.fixture, null); } catch (Exception ex) { tc.message = ex.Message; tc.stack = ex.StackTrace; throw; } }
public void EndFixture(TestCollection tc) { try { if (tc.classTeardown != null) tc.classTeardown.Invoke(tc.fixture, null); } catch (Exception ex) { tc.message = ex.Message; tc.stack = ex.StackTrace; throw; } }