コード例 #1
0
 public void OrderedStepsTest()
 {
     OrderedTest.Run(TestContext, new List <OrderedTest>
     {
         new OrderedTest(login_tc.LoginPageUI, false),
         new OrderedTest(login_tc.AdminLogIn, false),
         new OrderedTest(login_tc.LogOut, true)    // continue on failure
         // ...
     });
 }
コード例 #2
0
ファイル: OrderedTestUtil.cs プロジェクト: kaush7532/IXMWEBv2
        /// <summary>
        /// Run a list of OrderedTest's
        /// </summary>
        static public void Run(TestContext testContext, List <OrderedTest> tests)
        {
            Stopwatch overallStopWatch = new Stopwatch();

            overallStopWatch.Start();

            List <Exception> exceptions = new List <Exception>();

            int testsAttempted = 0;

            for (int i = 0; i < tests.Count; i++)
            {
                OrderedTest test = tests[i];

                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                testContext.WriteLine("Starting ordered test step ({0} of {1}) '{2}' at {3}...\n",
                                      i + 1,
                                      tests.Count,
                                      test.TestMethod.Method,
                                      DateTime.Now.ToString("G"));

                try
                {
                    testsAttempted++;
                    test.Run();
                }
                catch
                {
                    if (!test.ContinueOnFailure)
                    {
                        break;
                    }
                }
                finally
                {
                    Exception testEx = test.ExceptionResult;

                    if (testEx != null)  // capture any "continue on fail" exception
                    {
                        exceptions.Add(testEx);
                    }

                    testContext.WriteLine("\n{0} ordered test step {1} of {2} '{3}' in {4} at {5}{6}\n",
                                          testEx != null ? "Error:  Failed" : "Successfully completed",
                                          i + 1,
                                          tests.Count,
                                          test.TestMethod.Method,
                                          stopWatch.ElapsedMilliseconds > 1000
                            ? (stopWatch.ElapsedMilliseconds * .001) + "s"
                            : stopWatch.ElapsedMilliseconds + "ms",
                                          DateTime.Now.ToString("G"),
                                          testEx != null
                            ? "\nException:  " + testEx.Message +
                                          "\nStackTrace:  " + testEx.StackTrace +
                                          "\nContinueOnFailure:  " + test.ContinueOnFailure
                            : "");
                }
            }

            testContext.WriteLine("Completed running {0} of {1} ordered tests with a total of {2} error(s) at {3} in {4}",
                                  testsAttempted,
                                  tests.Count,
                                  exceptions.Count,
                                  DateTime.Now.ToString("G"),
                                  overallStopWatch.ElapsedMilliseconds > 1000
                    ? (overallStopWatch.ElapsedMilliseconds * .001) + "s"
                    : overallStopWatch.ElapsedMilliseconds + "ms");

            if (exceptions.Any())
            {
                // Test Explorer prints better msgs with this hierarchy rather than using 1 AggregateException().
                throw new Exception(String.Join("; ", exceptions.Select(e => e.Message), new AggregateException(exceptions)));
            }
        }