Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98800

Retry failed tests in MStest

$
0
0

Help me figure out how to restart tests for mstest (I just switched to it). I know that there is no built-in restart functionality, but I know that you can create custom attributes. I tried creating a "retry" attribute, but it doesn't rerun the tests if they fail.

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]    public class RetryAttribute : TestMethodAttribute    {        private readonly int _tryCount;        public RetryAttribute(int tryCount)        {            _tryCount = tryCount;        }        public override TestResult[] Execute(ITestMethod testMethod)        {            var results = new List<TestResult>();            for (int i = 0; i <= _tryCount; i++)            {                TestResult result = base.Execute(testMethod)[0];                results.Add(result);                if (result.Outcome == UnitTestOutcome.Passed)                    break;                if (i < _tryCount)                {                    Logger.LogMessage($"Retry {i + 1}/{_tryCount} for test {testMethod.TestMethodName}");                }            }            return results.ToArray();        }    }

Viewing all articles
Browse latest Browse all 98800


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>