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.

UnitySetUpAttribute.cs 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using System;
  2. using NUnit.Framework;
  3. namespace UnityEngine.TestTools
  4. {
  5. /// <summary>
  6. /// The `UnitySetUp` and <see cref="UnityTearDownAttribute"/> attributes are identical to the standard `SetUp` and `TearDown` attributes, with the exception that they allow for <see cref="IEditModeTestYieldInstruction"/>. The `UnitySetUp` and `UnityTearDown` attributes expect a return type of [IEnumerator](https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerator?view=netframework-4.8).
  7. /// </summary>
  8. /// <example>
  9. /// <code>
  10. /// <![CDATA[
  11. /// public class SetUpTearDownExample
  12. /// {
  13. /// [UnitySetUp]
  14. /// public IEnumerator SetUp()
  15. /// {
  16. /// yield return new EnterPlayMode();
  17. /// }
  18. ///
  19. /// [Test]
  20. /// public void MyTest()
  21. /// {
  22. /// Debug.Log("This runs inside playmode");
  23. /// }
  24. ///
  25. /// [UnityTearDown]
  26. /// public IEnumerator TearDown()
  27. /// {
  28. /// yield return new ExitPlayMode();
  29. /// }
  30. /// }
  31. /// ]]>
  32. /// </code>
  33. /// </example>
  34. /// <example>
  35. /// ## Base and Derived class example
  36. /// <code>
  37. /// <![CDATA[
  38. /// public class BaseClass
  39. /// {
  40. /// [OneTimeSetUp]
  41. /// public void OneTimeSetUp()
  42. /// {
  43. /// Debug.Log("OneTimeSetUp Base");
  44. /// }
  45. ///
  46. /// [SetUp]
  47. /// public void SetUp()
  48. /// {
  49. /// Debug.Log("SetUp Base");
  50. /// }
  51. ///
  52. /// [UnitySetUp]
  53. /// public IEnumerator UnitySetUp()
  54. /// {
  55. /// Debug.Log("UnitySetup Base");
  56. /// yield return null;
  57. /// }
  58. ///
  59. /// [TearDown]
  60. /// public void TearDown()
  61. /// {
  62. /// Debug.Log("TearDown Base");
  63. /// }
  64. ///
  65. /// [UnityTearDown]
  66. /// public IEnumerator UnityTearDown()
  67. /// {
  68. /// Debug.Log("UnityTearDown Base");
  69. /// yield return null;
  70. /// }
  71. /// }
  72. ///
  73. /// public class DerivedClass : BaseClass
  74. /// {
  75. /// [OneTimeSetUp]
  76. /// public new void OneTimeSetUp()
  77. /// {
  78. /// Debug.Log("OneTimeSetUp");
  79. /// }
  80. ///
  81. /// [SetUp]
  82. /// public new void SetUp()
  83. /// {
  84. /// Debug.Log("SetUp");
  85. /// }
  86. ///
  87. /// [UnitySetUp]
  88. /// public new IEnumerator UnitySetUp()
  89. /// {
  90. /// Debug.Log("UnitySetup");
  91. /// yield return null;
  92. /// }
  93. ///
  94. /// [Test]
  95. /// public void UnitTest()
  96. /// {
  97. /// Debug.Log("Test");
  98. /// }
  99. ///
  100. /// [UnityTest]
  101. /// public IEnumerator UnityTest()
  102. /// {
  103. /// Debug.Log("UnityTest before yield");
  104. /// yield return null;
  105. /// Debug.Log("UnityTest after yield");
  106. /// }
  107. ///
  108. /// [TearDown]
  109. /// public new void TearDown()
  110. /// {
  111. /// Debug.Log("TearDown");
  112. /// }
  113. ///
  114. /// [UnityTearDown]
  115. /// public new IEnumerator UnityTearDown()
  116. /// {
  117. /// Debug.Log("UnityTearDown");
  118. /// yield return null;
  119. /// }
  120. ///
  121. /// [OneTimeTearDown]
  122. /// public void OneTimeTearDown()
  123. /// {
  124. /// Debug.Log("OneTimeTearDown");
  125. /// }
  126. /// }
  127. /// ]]>
  128. /// </code>
  129. /// </example>
  130. /// <example>
  131. /// ## Domain reload example
  132. /// <code>
  133. /// <![CDATA[
  134. /// public class BaseClass
  135. /// {
  136. /// [OneTimeSetUp]
  137. /// public void OneTimeSetUp()
  138. /// {
  139. /// Debug.Log("OneTimeSetUp Base");
  140. /// }
  141. ///
  142. /// [SetUp]
  143. /// public void SetUp()
  144. /// {
  145. /// Debug.Log("SetUp Base");
  146. /// }
  147. ///
  148. /// [UnitySetUp]
  149. /// public IEnumerator UnitySetUp()
  150. /// {
  151. /// Debug.Log("UnitySetup Base");
  152. /// yield return null;
  153. /// }
  154. ///
  155. /// [TearDown]
  156. /// public void TearDown()
  157. /// {
  158. /// Debug.Log("TearDown Base");
  159. /// }
  160. ///
  161. /// [UnityTearDown]
  162. /// public IEnumerator UnityTearDown()
  163. /// {
  164. /// Debug.Log("UnityTearDown Base");
  165. /// yield return null;
  166. /// }
  167. /// }
  168. ///
  169. /// public class DerivedClass : BaseClass
  170. /// {
  171. /// [OneTimeSetUp]
  172. /// public new void OneTimeSetUp()
  173. /// {
  174. /// Debug.Log("OneTimeSetUp");
  175. /// }
  176. ///
  177. /// [SetUp]
  178. /// public new void SetUp()
  179. /// {
  180. /// Debug.Log("SetUp");
  181. /// }
  182. ///
  183. /// [UnitySetUp]
  184. /// public new IEnumerator UnitySetUp()
  185. /// {
  186. /// Debug.Log("UnitySetup");
  187. /// yield return null;
  188. /// }
  189. ///
  190. /// [Test]
  191. /// public void UnitTest()
  192. /// {
  193. /// Debug.Log("Test");
  194. /// }
  195. ///
  196. /// [UnityTest]
  197. /// public IEnumerator UnityTest()
  198. /// {
  199. /// Debug.Log("UnityTest before yield");
  200. /// yield return new EnterPlayMode();
  201. /// //Domain reload happening
  202. /// yield return new ExitPlayMode();
  203. /// Debug.Log("UnityTest after yield");
  204. /// }
  205. ///
  206. /// [TearDown]
  207. /// public new void TearDown()
  208. /// {
  209. /// Debug.Log("TearDown");
  210. /// }
  211. ///
  212. /// [UnityTearDown]
  213. /// public new IEnumerator UnityTearDown()
  214. /// {
  215. /// Debug.Log("UnityTearDown");
  216. /// yield return null;
  217. /// }
  218. ///
  219. /// [OneTimeTearDown]
  220. /// public void OneTimeTearDown()
  221. /// {
  222. /// Debug.Log("OneTimeTearDown");
  223. /// }
  224. /// }
  225. /// ]]>
  226. /// </code>
  227. /// </example>
  228. [AttributeUsage(AttributeTargets.Method)]
  229. public class UnitySetUpAttribute : NUnitAttribute
  230. {
  231. }
  232. }