internal static void Initialize(string test) { m_passCount = 0; m_failCount = 0; m_skipCount = 0; m_knownFailureCount = 0; SpotTestLog.StartTestLog(test); Log.StartMethod("Initialize"); }
/// <summary> /// This method will execute the tests specified in the argument. /// </summary> /// <param name="objects">A list of test objects.</param> public void Run(object[] objects) { foreach (string arg in objects) { // Binding flags for the type of methods in the test assembly you want to get info about. BindingFlags bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod; // Get all the types from the entry assembly. Type[] interfaces = Assembly.GetEntryAssembly().GetTypes(); // Find the ones that match the list of tests we are trying to run. foreach (Type t in interfaces) { if (string.Equals(t.Name.ToLower(), arg.ToLower()) && t.GetInterface("IMFTestInterface") != null) { ConstructorInfo ci = t.GetConstructor(new Type[0]); IMFTestInterface imf = null; bool initializedLog = false; InitializeResult initResult; try { // Invoke the constructor. imf = (IMFTestInterface)ci.Invoke(new object[0]); // Call Initialize. Log.Initialize(t.Name); initializedLog = true; initResult = imf.Initialize(); } catch (NotSupportedException) { initResult = InitializeResult.Skip; } if (InitializeResult.ReadyToGo == initResult) { Log.EndMethod("Initialize"); } else { if (initializedLog) { Log.EndMethod("Initialize"); } else { SpotTestLog.StartTestLog(t.Name); } // Get all the methods in the suite and log them as skipped. MethodInfo[] skipMethods = t.GetMethods(bf); foreach (MethodInfo method in skipMethods) { Type returnType = method.ReturnType; if (returnType == typeof(MFTestResults)) { Log.StartTestMethod(method.Name); Log.TestResult("TEST: " + method.Name, MFTestResults.Skip); Log.EndTestMethod(); } } Log.StartMethod("CleanUp"); Log.CleanUp(t.Name); // Reset counts and continue to the next test suite class. Log.ResetCounts(); continue; } // Get all the methods and call the one that matches the return type for test methods. MethodInfo[] methods = t.GetMethods(bf); foreach (MethodInfo method in methods) { Type returnType = method.ReturnType; if (returnType != typeof(MFTestResults)) { continue; } else { Log.StartTestMethod(method.Name); try { object result = method.Invoke(imf, new object[0]); switch ((int)result) { case (int)MFTestResults.Fail: Log.TestResult("TEST: " + method.Name, MFTestResults.Fail); break; case (int)MFTestResults.Pass: Log.TestResult("TEST: " + method.Name, MFTestResults.Pass); break; case (int)MFTestResults.Skip: Log.TestResult("TEST: " + method.Name, MFTestResults.Skip); break; case (int)MFTestResults.KnownFailure: Log.TestResult("TEST: " + method.Name, MFTestResults.KnownFailure); break; } } catch (Exception ex) { Log.Comment("#########START STACK TRACE#########"); Log.Comment(ex.StackTrace); Log.Comment("#########END STACK TRACE#########"); Log.TestResult("TEST: " + method.Name + " threw an unhandled exception", MFTestResults.Fail); Log.EndTestMethod(); Log.StartMethod("CleanUp"); Log.CleanUp(t.Name); throw ex; } Log.EndTestMethod(); } } // Call cleanup. Log.StartMethod("CleanUp"); imf.CleanUp(); Log.CleanUp(t.Name); } } } }