public void LoadAssemblyTestCases(Assembly assembly) { foreach (Type t in assembly.GetTypes()) { if (t.GetCustomAttributes(typeof(TestSetAttribute), true).Length > 0) { bool allTargets = (Filters == null || Filters.Length == 0) || Filters.Any(f => f.StartsWith(t.Name)); TestSetAttribute testSetAttr = t.GetCustomAttributes( typeof(TestSetAttribute), true)[0] as TestSetAttribute; #if DEBUG if (testSetAttr != null && testSetAttr.DebugEnabled) #else if (testSetAttr != null && testSetAttr.ReleaseEnabled) #endif { object testSetInstance = System.Activator.CreateInstance(t); if (testSetInstance != null) { TestSetInfo testSetInfo = new TestSetInfo() { Instance = testSetInstance, Name = t.Name, }; foreach (MethodInfo method in testSetInstance.GetType().GetMethods( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if ((allTargets || ((Filters == null || Filters.Length == 0) || Filters.Any(f => method.Name.StartsWith(f, StringComparison.CurrentCultureIgnoreCase)))) && method.GetCustomAttributes(typeof(TestCaseAttribute), false).Length > 0) { TestCaseAttribute testCaseAttr = method.GetCustomAttributes(typeof(TestCaseAttribute), false)[0] as TestCaseAttribute; if (testCaseAttr != null && ((Filters != null && Filters.Any(f => method.Name.Contains(f))) || testCaseAttr.DebugEnabled)) { TestCaseInfo testCaseInfo = new TestCaseInfo { Name = method.Name, Method = method, Sort = testCaseAttr.Sort, }; testSetInfo.TestCases.Add(testCaseInfo); } } } if (testSetInfo.TestCases.Count > 0) { testSets.Add(testSetInfo); } } } } } }
internal bool RunTestCase(TestSetInfo testSetInfo, TestCaseInfo testCaseInfo, List <string> failList) { object testSet = testSetInfo.Instance; stop.Reset(); if (BeforePerformTestCase != null) { var evtArg = new TestCaseEventArgs(testSetInfo, testCaseInfo); BeforePerformTestCase(this, evtArg); if (evtArg.Cancel) { return(true); } } GC.Collect(0, GCCollectionMode.Forced); long mem = GetProcessMemoryUsage(); stop.Start(); try { testCaseInfo.Method.Invoke(testSet, null); } catch (TargetInvocationException x) { testCaseInfo.Exception = x.InnerException; if (failList != null) { failList.Add(testSetInfo.Name + "." + testCaseInfo.Name); } } catch (TestCaseFailureException x) { testCaseInfo.Exception = x; if (failList != null) { failList.Add(testSetInfo.Name + "." + testCaseInfo.Name); } } stop.Stop(); testCaseInfo.Performed = true; testCaseInfo.ElapsedMilliseconds = stop.ElapsedMilliseconds; testCaseInfo.MemoryUsage = GetProcessMemoryUsage() - mem; GC.Collect(0, GCCollectionMode.Forced); if (AfterPerformTestCase != null) { AfterPerformTestCase(this, new TestCaseEventArgs(testSetInfo, testCaseInfo)); } return(testCaseInfo.Exception != null); }
private ListViewItem GetItemByTestSetInfo(TestSetInfo testSetInfo) { foreach (ListViewItem item in caseList.Items) { if (item.Tag == testSetInfo) { return(item); } } return(null); }
public bool RunTestSet(TestSetInfo testSetInfo, List <string> failList) { testSetInfo.Reset(); var arg = new TestSetEventArgs(testSetInfo); if (StartTestSet != null) { StartTestSet(this, arg); } if (arg.Cancelled) { return(true); } try { if (testSetInfo.Instance is TestSet) { ((TestSet)testSetInfo.Instance).SetUp(); } } catch { } foreach (TestCaseInfo testCaseInfo in testSetInfo.TestCases.OrderBy(tc => tc.Sort)) { RunTestCase(testSetInfo, testCaseInfo, failList); } try { if (testSetInfo.Instance is TestSet) { ((TestSet)testSetInfo.Instance).SetDown(); } } catch { } if (FinishTestSet != null) { FinishTestSet(this, new TestSetEventArgs(testSetInfo)); } return(testSetInfo.IsAllSuccessed); }
public TestCaseEventArgs(TestSetInfo testSetInfo, TestCaseInfo testCaseInfo) { this.testSetInfo = testSetInfo; this.testCaseInfo = testCaseInfo; }
public TestSetEventArgs(TestSetInfo testSetInfo) { this.testSetInfo = testSetInfo; }