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