Ejemplo n.º 1
0
        public override TestResult[] Execute(
            ITestMethod testMethod)
        {
            // NOTE
            // This implementation will need to be refactored as we add more
            // execution variations.

            int retryCount  = 1;
            int repeatCount = 1;

            Attribute[] attr = testMethod.GetAllAttributes(false);
            if (attr == null)
            {
                Attribute[] r1    = testMethod.GetAttributes <RetryAttribute>(false);
                var         attr2 = new List <Attribute>();
                attr2.AddRange(r1);

                r1 = testMethod.GetAttributes <RepeatAttribute>(false);
                attr2.AddRange(r1);

                attr = attr2.ToArray();
            }

            if (attr != null)
            {
                foreach (Attribute a in attr)
                {
                    if (a is RetryAttribute retryAttr)
                    {
                        retryCount = retryAttr.Value;
                    }

                    if (a is RepeatAttribute repeatAttr)
                    {
                        repeatCount = repeatAttr.Value;
                    }
                }
            }

            var res = executeWithRepeatAndRetry(testMethod, repeatCount, retryCount);

            return(res);
        }
Ejemplo n.º 2
0
 public Attribute[] GetAllAttributes(bool inherit)
 {
     return(_target.GetAllAttributes(inherit));
 }
        public override TestResult[] Execute(ITestMethod testMethod)
        {
            // NOTE
            // This implementation will need to be refactored as we add more
            // execution variations.

            int  retryCount = 1;
            Type eet        = null;

            Attribute[] attr = testMethod.GetAllAttributes(false);

            if (attr != null)
            {
                foreach (Attribute a in attr)
                {
                    if (a is RetryAttribute)
                    {
                        RetryAttribute retryAttr = (RetryAttribute)a;
                        retryCount = int.Parse(retryAttr.Value);
                    }

                    if (a is ExpectedExceptionAttribute)
                    {
                        ExpectedExceptionAttribute eea = (ExpectedExceptionAttribute)a;
                        eet = eea.ExceptionType;
                    }
                }
            }

            TestResult[] results = null;
            var          res     = new List <TestResult>();

            var currentCount = 0;

            while (currentCount < retryCount)
            {
                currentCount++;

                try
                {
                    results = base.Execute(testMethod);
                }
                catch (Exception e)
                {
                    if (eet == null)
                    {
                        break;
                    }

                    if (e.GetType().Equals(eet) == false)
                    {
                        break;
                    }
                }

                if (results == null)
                {
                    continue;
                }

                foreach (var testResult in results)
                {
                    testResult.DisplayName = $"{testMethod.TestMethodName} - Execution number {currentCount}";
                }
                res.AddRange(results);

                if (results.Any((tr) => tr.Outcome == UnitTestOutcome.Failed))
                {
                    continue;
                }

                break;
            }

            return(res.ToArray());
        }
Ejemplo n.º 4
0
 public Attribute[] GetAllAttributes(bool inherit) => _target.GetAllAttributes(inherit);