예제 #1
0
        public ITestResult Run(TestMethodInstance instance)
        {
            var result = RunOnce(instance);

            while (RetryAnalyser(result))
            {
                Runner.Log("RETRYING");
                var newResult = RunOnce(instance);
                newResult.AddRetriedResult(result);
                result = newResult;
            }
            return(result);
        }
예제 #2
0
        private void InvokeWithTimeout(TestMethodInstance instance, ITestResult result)
        {
            var tokenSource = new CancellationTokenSource();
            var token       = tokenSource.Token;
            var timeOut     = instance.Attr.TimeoutSeconds * 1000;

            var context = WebContext.GetThreadLocalContext();
            var task    = Task.Factory.StartNew(() =>
            {
                WebContext.Set(context);
                TestResultReporter.Set(result);
                instance.Invoke();
            }, token);

            if (!task.Wait(timeOut, token))
            {
                throw new WebDriverTimeoutException("test timed out after " + instance.Attr.TimeoutSeconds + " sec");
            }
        }
예제 #3
0
        private ITestResult RunOnce(TestMethodInstance instance)
        {
            ITestResult result = new TestResult(instance);

            TestResultReporter.Set(result);

            // the instance couldn't be constructed properly, and cannot be run.
            if (instance.RunnerException != null)
            {
                result.Exception = instance.RunnerException;
                result.Status    = Status.Skipped;
                return(result);
            }

            try
            {
                // TODO freynaud check parameters for missmatch before running beforeMethod.
                foreach (var listener in _listeners)
                {
                    listener.OnTestStart(instance, result);
                }
            }
            catch (Exception e)
            {
                result.Exception = e.InnerException;
                result.Status    = Status.Skipped;
                foreach (var listener in _listeners)
                {
                    listener.OnTestSkipped(instance, result);
                }
                result.StopWatch();
                TestResultReporter.Clear();
                return(result);
            }

            try
            {
                //instance.Invoke();
                InvokeWithTimeout(instance, result);
                result.Status = Status.Passed;

                foreach (var listener in _listeners)
                {
                    listener.OnTestPassed(instance, result);
                }
            }
            catch (Exception e)
            {
                //TestResultReporter.Log(e.Message);
                // reflection + another thread. Needs to go 2 level down.
                // except when it times out
                result.Exception = e.InnerException == null ? e : e.InnerException.InnerException;
                if (e.InnerException != null && e.InnerException.InnerException != null && e.InnerException.InnerException.GetType().Name == "InconclusiveException")
                {
                    result.Status = Status.Skipped;
                }
                else
                {
                    result.Status = Status.Failed;
                }
                foreach (var listener in _listeners)
                {
                    if (result.Status == Status.Skipped)
                    {
                        try
                        {
                            listener.OnTestSkipped(instance, result);
                        }
                        catch (Exception tle)
                        {
                            result.Log("WARNING. A OnTestSkipped() listener skipped with the following message :" + tle.Message);
                        }
                    }
                    else
                    {
                        try
                        {
                            listener.OnTestFailed(instance, result);
                        }
                        catch (Exception tle)
                        {
                            result.Log("WARNING. A OnTestFailed() listener failed with the following error :" + tle.Message);
                        }
                    }
                }
            }
            finally
            {
                // TODO freynaud the order needs to be reversed. First listener executed last makes more sense.
                foreach (var listener in _listeners)
                {
                    try
                    {
                        listener.OnTestFinished(instance, result);
                    }
                    catch (Exception e)
                    {
                        Runner.Log("OnTestFinished ERROR " + e);
                    }
                }
            }
            result.StopWatch();
            TestResultReporter.Clear();
            return(result);
        }