No Description
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.

DefaultTestWorkItem.cs 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections;
  3. using NUnit.Framework.Interfaces;
  4. using NUnit.Framework.Internal;
  5. using NUnit.Framework.Internal.Commands;
  6. using UnityEngine.TestTools;
  7. namespace UnityEngine.TestRunner.NUnitExtensions.Runner
  8. {
  9. internal class EditModeTestCallbacks
  10. {
  11. public static Action RestoringTestContext { get; set; }
  12. }
  13. internal class DefaultTestWorkItem : UnityWorkItem
  14. {
  15. private TestCommand _command;
  16. public DefaultTestWorkItem(TestMethod test, ITestFilter filter)
  17. : base(test, null)
  18. {
  19. _command = TestCommandBuilder.BuildTestCommand(test, filter);
  20. }
  21. protected override IEnumerable PerformWork()
  22. {
  23. if (m_DontRunRestoringResult && EditModeTestCallbacks.RestoringTestContext != null)
  24. {
  25. EditModeTestCallbacks.RestoringTestContext();
  26. Result = Context.CurrentResult;
  27. yield break;
  28. }
  29. try
  30. {
  31. if (_command is SkipCommand || _command is FailCommand)
  32. {
  33. Result = _command.Execute(Context);
  34. yield break;
  35. }
  36. if (!(_command is IEnumerableTestMethodCommand))
  37. {
  38. Debug.LogError("Cannot perform work on " + _command.GetType().Name);
  39. yield break;
  40. }
  41. if (Context.TestCaseTimeout == 0)
  42. {
  43. Context.TestCaseTimeout = k_DefaultTimeout;
  44. }
  45. foreach (var workItemStep in ((IEnumerableTestMethodCommand)_command).ExecuteEnumerable(Context))
  46. {
  47. ResultedInDomainReload = false;
  48. if (workItemStep is IEditModeTestYieldInstruction)
  49. {
  50. var editModeTestYieldInstruction = (IEditModeTestYieldInstruction)workItemStep;
  51. yield return editModeTestYieldInstruction;
  52. var enumerator = editModeTestYieldInstruction.Perform();
  53. while (true)
  54. {
  55. bool moveNext;
  56. try
  57. {
  58. moveNext = enumerator.MoveNext();
  59. }
  60. catch (Exception e)
  61. {
  62. Context.CurrentResult.RecordException(e);
  63. break;
  64. }
  65. if (!moveNext)
  66. {
  67. break;
  68. }
  69. yield return null;
  70. }
  71. }
  72. else
  73. {
  74. yield return workItemStep;
  75. }
  76. }
  77. Result = Context.CurrentResult;
  78. }
  79. finally
  80. {
  81. WorkItemComplete();
  82. }
  83. }
  84. }
  85. }