UnitySetUpAttribute.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. /// <example>
  8. /// <code>
  9. ///public class SetUpTearDownExample
  10. /// {
  11. /// [UnitySetUp]
  12. /// public IEnumerator SetUp()
  13. /// {
  14. /// yield return new EnterPlayMode();
  15. /// }
  16. ///
  17. /// [Test]
  18. /// public void MyTest()
  19. /// {
  20. /// Debug.Log("This runs inside playmode");
  21. /// }
  22. ///
  23. /// [UnityTearDown]
  24. /// public IEnumerator TearDown()
  25. /// {
  26. /// yield return new ExitPlayMode();
  27. /// }
  28. /// }
  29. /// </code>
  30. /// </example>
  31. /// </summary>
  32. [AttributeUsage(AttributeTargets.Method)]
  33. public class UnitySetUpAttribute : NUnitAttribute
  34. {
  35. }
  36. }