private void RunTestMethod(TestDef test, object classObj, MethodInfo starter, MethodInfo setup, MethodInfo closer, string filter, int totalNoTestsToRun) { if (_filenamesThatStopTheTestRun.Any(File.Exists)) { Log.Debug("Found file defined to stop test-run"); return; } MethodInfo testmethod = test.Test; TestsRun++; Log.DebugFormat(Environment.NewLine + "{0}/{1} - {2} - E:{3} {4} - {2}", TestsRun, totalNoTestsToRun, test.i, ErrorCount, test.CompleteTestName); if ((filter != "" && !testmethod.Name.ToLower().StartsWith(filter.ToLower())) || FilterByUserHook(test.CompleteTestName)) return; if (ResetTestEnvironment != null) ResetTestEnvironment(); try { setup.Invoke(classObj, emptyParams); } catch (Exception ex) { ErrorCount++; Log.Error("Error setting up environment: " + ex.Message, ex); return; } try { starter.Invoke(classObj, emptyParams); } catch (Exception ex) { ErrorCount++; Log.Error("Error starting program: " + ex.Message, ex); //On error wait a bit extra in case the program is hanging Thread.Sleep(5000); CloseProgram(closer, classObj, emptyParams); return; } try { testmethod.Invoke(classObj, emptyParams); } catch (Exception ex) { ErrorCount++; string filename = ""; try { filename = ScreenShooter.SaveToFile(); } catch (Exception innerEx) { ErrorCount++; Log.Error("Exception while trying to save screenshot: " + innerEx.Message, innerEx); } Log.Error(ex.Message + " screenshot: " + filename, ex); if (ex.InnerException != null) { Log.Error(ex.InnerException.Message, ex.InnerException); } try { Log.Error("Latest unique identifiers: " + UiTestDslCoreCommon.UniqueIdentifier + " / " + UiTestDslCoreCommon.shortUnique); } catch (Exception) { } if (ErrorHook != null) ErrorHook(test.CompleteTestName); } CloseProgram(closer, classObj, emptyParams); Log.Debug("-- Test # " + test.i + " done, current error count: " + ErrorCount + " \n\n"); //Need to allow the program time to exit, to avoid the next test finding an open program while starting. Thread.Sleep(3000); }
private List<TestDef> GetAllTests(Assembly testAssembly, List<string> skipOnThisComputer) { Type[] classes = testAssembly.GetTypes(); List<TestDef> tests = new List<TestDef>(); int i = 1; foreach (Type testclass in classes) { if (!testclass.IsDefined(typeof(TestClassAttribute), false)) continue; MethodInfo[] methods = testclass.GetMethods(); foreach (MethodInfo testmethod in methods) { if (testmethod.IsDefined(typeof(TestMethodAttribute), true)) { var t = new TestDef { TestClass = testclass, Test = testmethod, }; if (skipOnThisComputer.Contains(t.CompleteTestName)) continue; t.i = i++; tests.Add(t); } } } return tests; }