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

IOuterUnityTestAction.cs 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections;
  3. using NUnit.Framework.Interfaces;
  4. namespace UnityEngine.TestTools
  5. {
  6. /// <summary>
  7. /// An attribute can implement this interface to provide actions to execute before setup and after teardown of tests.
  8. /// </summary>
  9. /// <example>
  10. /// ## IOuterUnityTestAction Example
  11. /// <code>
  12. /// <![CDATA[
  13. /// using System.Collections;
  14. /// using NUnit.Framework;
  15. /// using NUnit.Framework.Interfaces;
  16. /// using UnityEngine;
  17. /// using UnityEngine.TestTools;
  18. ///
  19. /// public class MyTestClass
  20. /// {
  21. /// [UnityTest, MyOuterActionAttribute]
  22. /// public IEnumerator MyTestInsidePlaymode()
  23. /// {
  24. /// Assert.IsTrue(Application.isPlaying);
  25. /// yield return null;
  26. /// }
  27. /// }
  28. ///
  29. /// public class MyOuterActionAttribute : NUnitAttribute, IOuterUnityTestAction
  30. /// {
  31. /// public IEnumerator BeforeTest(ITest test)
  32. /// {
  33. /// yield return new EnterPlayMode();
  34. /// }
  35. ///
  36. /// public IEnumerator AfterTest(ITest test)
  37. /// {
  38. /// yield return new ExitPlayMode();
  39. /// }
  40. /// }
  41. /// ]]>
  42. /// </code>
  43. /// </example>
  44. /// <example>
  45. /// ## Test actions with domain reload example
  46. /// <code>
  47. /// <![CDATA[
  48. /// using NUnit.Framework.Interfaces;
  49. ///
  50. ///
  51. /// public class TestActionOnSuiteAttribute : NUnitAttribute, ITestAction
  52. /// {
  53. /// public void BeforeTest(ITest test)
  54. /// {
  55. /// Debug.Log("TestAction OnSuite BeforeTest");
  56. /// }
  57. ///
  58. /// public void AfterTest(ITest test)
  59. /// {
  60. /// }
  61. ///
  62. /// public ActionTargets Targets { get { return ActionTargets.Suite; } }
  63. /// }
  64. ///
  65. /// public class TestActionOnTestAttribute : NUnitAttribute, ITestAction
  66. /// {
  67. /// public void BeforeTest(ITest test)
  68. /// {
  69. /// Debug.Log("TestAction OnTest BeforeTest");
  70. /// }
  71. ///
  72. /// public void AfterTest(ITest test)
  73. /// {
  74. /// Debug.Log("TestAction OnTest AfterTest");
  75. /// }
  76. ///
  77. /// public ActionTargets Targets { get { return ActionTargets.Test; } }
  78. /// }
  79. ///
  80. /// public class OuterTestAttribute : NUnitAttribute, IOuterUnityTestAction
  81. /// {
  82. /// public IEnumerator BeforeTest(ITest test)
  83. /// {
  84. /// Debug.Log("OuterTestAttribute BeforeTest");
  85. /// yield return null;
  86. /// }
  87. ///
  88. /// public IEnumerator AfterTest(ITest test)
  89. /// {
  90. /// Debug.Log("OuterTestAttribute AfterTest");
  91. /// yield return null;
  92. /// }
  93. /// }
  94. ///
  95. /// [TestActionOnSuite]
  96. /// public class ActionOrderTestBase
  97. /// {
  98. /// [Test, OuterTest, TestActionOnTest]
  99. /// public void UnitTest()
  100. /// {
  101. /// Debug.Log("Test");
  102. /// }
  103. ///
  104. /// [UnityTest, OuterTest, TestActionOnTest]
  105. /// public IEnumerator UnityTestWithDomainReload()
  106. /// {
  107. /// Log("Test part 1");
  108. /// yield return new EnterPlayMode();
  109. /// //Domain reload
  110. /// yield return new ExitPlayMode();
  111. /// Log("Test part 2");
  112. /// }
  113. /// }
  114. /// ]]>
  115. /// </code>
  116. /// </example>
  117. public interface IOuterUnityTestAction
  118. {
  119. /// <summary>Executed before each test is run</summary>
  120. /// <param name="test">The test that is going to be run.</param>
  121. /// <returns>Enumerable collection of actions to perform before test setup.</returns>
  122. IEnumerator BeforeTest(ITest test);
  123. /// <summary>Executed after each test is run</summary>
  124. /// <param name="test">The test that has just been run.</param>
  125. /// <returns>Enumerable collection of actions to perform after test teardown.</returns>
  126. IEnumerator AfterTest(ITest test);
  127. }
  128. }