Exemple #1
0
 internal static void Initialize(string test)
 {
     m_passCount         = 0;
     m_failCount         = 0;
     m_skipCount         = 0;
     m_knownFailureCount = 0;
     SpotTestLog.StartTestLog(test);
     Log.StartMethod("Initialize");
 }
 internal static void CleanUp(string test)
 {
     Log.EndMethod("CleanUp");
     SpotTestLog.StartNode("Results");
     LogPassCount();
     LogFailCount();
     LogSkipCount();
     LogKnownFailureCount();
     SpotTestLog.EndNode("Results");
     SpotTestLog.EndTestLog(test);
     System.Threading.Thread.Sleep(2000);
 }
 private static void LogKnownFailureCount()
 {
     SpotTestLog.WriteRaw("\t<KnownFailureCount>" + "<Text>" + m_knownFailureCount.ToString() + "</Text>"
                          + "<Date>" + GetDate() + "</Date>" + "<Time>" + DateTime.Now.TimeOfDay.ToString()
                          + "</Time>" + "</KnownFailureCount>");
 }
 private static void LogSkipCount()
 {
     SpotTestLog.WriteRaw("\t<SkipCount>" + "<Text>" + m_skipCount.ToString() + "</Text>"
                          + "<Date>" + GetDate() + "</Date>" + "<Time>" + DateTime.Now.TimeOfDay.ToString()
                          + "</Time>" + "</SkipCount>");
 }
 internal static void EndMethod(string name)
 {
     SpotTestLog.EndNode(name);
 }
 internal static void StartMethod(string name)
 {
     SpotTestLog.StartNode(name);
 }
 internal static void EndTestMethod()
 {
     SpotTestLog.EndTestMethod();
 }
 internal static void WriteMessage(string message)
 {
     SpotTestLog.WriteRaw("\t\t" + "<Text><![CDATA[" + message + "]]></Text>" +
                          "<Date>" + GetDate() + "</Date>" +
                          "<Time>" + DateTime.Now.TimeOfDay.ToString() + "</Time>");
 }
        /// <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);
                    }
                }
            }
        }