Yield instructions for the Editor
Yield instructions for the Unity Editor from your Edit mode tests, using either a set of pre-defined common instructions or defining your own.
Read time 1 minuteLast updated 13 days ago
One of the key additions a provides over regular NUnit is the ability to yield instructions for the Unity Editor. From Unity tests you can skip frames and instruct the Editor to enter or exit Play mode, recompile scripts, or wait for a scheduled domain reload to finish.
[UnityTest][Test]The following commonly-used yield instructions are pre-defined:
You can also define additional custom yield instructions for the Unity Editor for use in your Edit mode tests. For more information on how to do this, including usage examples, refer to the interface API description.
IEditModeTestYieldInstructionFor more information on using the statement in C#, refer to yield statement.
yieldFor information on the use of -returned instructions for the Editor in Unity coroutines, refer to Splitting tasks across frames.
yieldYield a MonoBehaviour to test
Yield return a from a Unity test to instantiate the you want to test and wait for it to finish running. Implement the interface on the to define when the test completes. The following example demonstrates this:
MonoBehaviourTestMonoBehaviourIMonoBehaviourTestMonoBehaviour[UnityTest]public IEnumerator MonoBehaviourTest_Works(){ yield return new MonoBehaviourTest<MyMonoBehaviourTest>();}public class MyMonoBehaviourTest : MonoBehaviour, IMonoBehaviourTest{ private int frameCount; public bool IsTestFinished { get { return frameCount > 10; } } void Update() { frameCount++; }}