SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.0 KiB

4 years ago
  1. using System;
  2. using System.Collections;
  3. using System.Reflection;
  4. using NUnit.Framework;
  5. using NUnit.Framework.Interfaces;
  6. using NUnit.Framework.Internal;
  7. using NUnit.Framework.Internal.Commands;
  8. using UnityEngine.TestRunner.NUnitExtensions.Runner;
  9. namespace UnityEngine.TestTools
  10. {
  11. internal class EnumerableRetryTestCommand : DelegatingTestCommand, IEnumerableTestMethodCommand
  12. {
  13. private int retryCount;
  14. public EnumerableRetryTestCommand(RetryAttribute.RetryCommand commandToReplace) : base(commandToReplace.GetInnerCommand())
  15. {
  16. retryCount = (int) typeof(RetryAttribute.RetryCommand)
  17. .GetField("_retryCount", BindingFlags.NonPublic | BindingFlags.Instance)
  18. .GetValue(commandToReplace);
  19. }
  20. public override TestResult Execute(ITestExecutionContext context)
  21. {
  22. throw new NotImplementedException("Use ExecuteEnumerable");
  23. }
  24. public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
  25. {
  26. var unityContext = (UnityTestExecutionContext)context;
  27. int count = unityContext.EnumerableRetryTestState;
  28. while (count < retryCount)
  29. {
  30. count++;
  31. unityContext.EnumerableRetryTestState = count;
  32. if (innerCommand is IEnumerableTestMethodCommand)
  33. {
  34. var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
  35. foreach (var iterator in executeEnumerable)
  36. {
  37. yield return iterator;
  38. }
  39. }
  40. else
  41. {
  42. context.CurrentResult = innerCommand.Execute(context);
  43. }
  44. if (context.CurrentResult.ResultState != ResultState.Failure)
  45. {
  46. break;
  47. }
  48. }
  49. unityContext.EnumerableRetryTestState = 0;
  50. }
  51. }
  52. }