Exemplo n.º 1
0
        public void PostLoad()
        {
            bool failed      = false;
            var  failedtests = new List <string>();

            LogController.AddLogAction(AddLog);
            foreach (ITest test in m_Tests)
            {
                var tr = new TestResult
                {
                    Name    = test.GetType().FullName,
                    RunTime = Environment.TickCount
                };
                m_Log.Info("********************************************************************************");
                m_Log.InfoFormat("Executing test {0}", test.GetType().FullName);
                m_Log.Info("********************************************************************************");
                try
                {
                    ClearLog();
                    test.Setup();

                    if (test.Run())
                    {
                        tr.Message = "Success\n\nLog:\n" + GetLog();
                        tr.Result  = true;

                        m_Log.Info("********************************************************************************");
                        m_Log.InfoFormat("Executed test {0} with SUCCESS", test.GetType().FullName);
                        m_Log.Info("********************************************************************************");
                    }
                    else
                    {
                        failed     = true;
                        tr.Message = "Failure\n\nLog:\n" + GetLog();
                        tr.Result  = false;
                        failedtests.Add(test.GetType().FullName);

                        m_Log.Info("********************************************************************************");
                        m_Log.ErrorFormat("Executed test {0} with FAILURE", test.GetType().FullName);
                        m_Log.Info("********************************************************************************");
                    }
                }
                catch (Exception e)
                {
                    failed        = true;
                    tr.Message    = string.Format("Exception {0}: {1}\n{2}\n\nLog:\n", e.GetType().FullName, e.ToString(), e.StackTrace.ToString()) + GetLog();
                    tr.Result     = false;
                    tr.StackTrace = e.StackTrace;
                    if (!failedtests.Contains(test.GetType().FullName))
                    {
                        failedtests.Add(test.GetType().FullName);
                    }

                    m_Log.Info("********************************************************************************");
                    m_Log.InfoFormat("Executed test {0} with FAILURE", test.GetType().FullName);
                    m_Log.ErrorFormat("Exception {0}: {1}\n{2}", e.GetType().FullName, e.ToString(), e.StackTrace.ToString());
                    m_Log.Info("********************************************************************************");
                }

                try
                {
                    test.Cleanup();
                }
                catch (Exception e)
                {
                    m_Log.Info("********************************************************************************");
                    m_Log.InfoFormat("Executed test {0} with FAILURE (Cleanup)", test.GetType().FullName);
                    m_Log.ErrorFormat("Exception {0}: {1}\n{2}", e.GetType().FullName, e.ToString(), e.StackTrace.ToString());
                    m_Log.Info("********************************************************************************");
                    failed        = true;
                    tr.Message    = string.Format("Exception {0}: {1}\n{2}\n\nLog:\n", e.GetType().FullName, e.ToString(), e.StackTrace.ToString()) + GetLog();
                    tr.Result     = false;
                    tr.StackTrace = e.StackTrace;
                    if (!failedtests.Contains(test.GetType().FullName))
                    {
                        failedtests.Add(test.GetType().FullName);
                    }
                }

                if (ExcludeSummaryCount)
                {
                    tr.RunTime = 0;
                }
                else
                {
                    tr.RunTime = Environment.TickCount - tr.RunTime;
                }

                TestResults.Add(tr);
            }

            if (m_XUnitResultsFileName?.Length != 0)
            {
                WriteXUnitResults(m_XUnitResultsFileName);
            }

            if (m_NUnitResultsFileName?.Length != 0)
            {
                WriteNUnit2Results(m_NUnitResultsFileName);
            }

            if (failed)
            {
                m_Log.InfoFormat("Failed tests ({0}): {1}", failedtests.Count, string.Join(" ", failedtests));
                Thread.Sleep(100);
                throw new ConfigurationLoader.TestingErrorException();
            }
            else
            {
                ConfigurationLoader loader = m_Loader;
                if (null != loader)
                {
                    loader.TriggerShutdown();
                }
            }
        }