暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

EnumerableRetryTestCommand.cs 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.EnumerableTestState.Retry;
  28. var firstCycleAfterResume = count > 0;
  29. while (count < retryCount || (firstCycleAfterResume && count <= retryCount))
  30. {
  31. if (!firstCycleAfterResume)
  32. {
  33. count++;
  34. }
  35. firstCycleAfterResume = false;
  36. unityContext.EnumerableTestState.Retry = count;
  37. if (innerCommand is IEnumerableTestMethodCommand)
  38. {
  39. var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
  40. foreach (var iterator in executeEnumerable)
  41. {
  42. yield return iterator;
  43. }
  44. }
  45. else
  46. {
  47. context.CurrentResult = innerCommand.Execute(context);
  48. }
  49. if (context.CurrentResult.ResultState != ResultState.Failure)
  50. {
  51. break;
  52. }
  53. }
  54. unityContext.EnumerableTestState.Retry = 0;
  55. }
  56. }
  57. }