Пример #1
0
        /// <summary>
        /// Run tests and collect statistics.
        /// </summary>
        /// <param name="testClassStatistic">The test class statistics.</param>
        /// <param name="instance">The instance.</param>
        /// <param name="testMethod">The test method.</param>
        private static void Test(TestClassStatistic testClassStatistic, IPageObjectTests instance, MethodInfo testMethod)
        {
            Trace.WriteLine("Executing page test <" + testMethod.Name + ">");

            var startTimeForCurrentIteration = DateTime.Now;

            try
            {
                // execute test method
                testMethod.Invoke(instance, null);

                // add method statistics
                testClassStatistic += new TestMethodStatistic()
                {
                    MethodInfo = testMethod, PageType = instance.PageType, Info = "none", Start = startTimeForCurrentIteration, Success = true
                };
            }
            catch (Exception e)
            {
                Exception exceptionForTrace = e;

                if (e is System.Reflection.TargetInvocationException && e.InnerException != null)
                {
                    exceptionForTrace = e.InnerException;
                }

                Trace.WriteLine(string.Format("Exception in page test {0}: {1}", testMethod.Name, e.Message));
                Trace.WriteLine(exceptionForTrace.StackTrace);
                Trace.WriteLine(exceptionForTrace.ToString());

                // add method statistics
                testClassStatistic += new TestMethodStatistic()
                {
                    MethodInfo = testMethod, PageType = instance.PageType, Info = e.GetType().Name, Start = startTimeForCurrentIteration, Success = false
                };

                throw;
            }

            Trace.WriteLine("Page test finished: " + testMethod.Name);
            Trace.WriteLine("------------------------------------------------------------");
        }
Пример #2
0
        /// <summary>
        /// Run tests and collect statistics.
        /// </summary>
        /// <param name="testClassStatistic">The test class statistics.</param>
        /// <param name="instance">The instance.</param>
        /// <param name="testMethod">The test method.</param>
        private static void Test(TestClassStatistic testClassStatistic, IPageObjectTests instance, MethodInfo testMethod)
        {
            Trace.WriteLine($"Executing page test <{testMethod.Name}>");

            var startTimeForCurrentIteration = DateTime.Now;

            try
            {
                // execute test method
                testMethod.Invoke(instance, null);

                // add method statistics
                testClassStatistic += new TestMethodStatistic()
                {
                    MethodInfo = testMethod, Info = null, Start = startTimeForCurrentIteration, Success = true
                };
            }
            catch (Exception e)
            {
                Exception exceptionForTrace = e;
                if (e is TargetInvocationException && e.InnerException != null)
                {
                    exceptionForTrace = e.InnerException;
                }

                Trace.WriteLine($"Exception in page test {testMethod.Name}: {e.Message}{Environment.NewLine}{exceptionForTrace.StackTrace}{Environment.NewLine}{exceptionForTrace.ToString()}");

                // add method statistics
                testClassStatistic += new TestMethodStatistic()
                {
                    MethodInfo = testMethod, Info = e.GetType().Name, Start = startTimeForCurrentIteration, Success = false
                };

                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
            }

            Trace.WriteLine($"Page test finished: {testMethod.Name}{Environment.NewLine}------------------------------------------------------------");
        }