Edit mode and Play mode tests
Define tests as either Edit mode or Play mode depending on the context they run in.
Read time 2 minutesLast updated 13 days ago
Unity Test Framework identifies tests as either Edit mode tests or Play mode tests depending on the references of their parent assembly.
Edit mode tests
Edit mode tests (also known as Editor tests) only run in the Unity Editor and have access to Editor code and runtime application code. As such, Edit mode test assemblies can reference code in both the and namespaces.
UnityEditorUnityEngineWith Edit mode tests you can test any of your Editor extensions using the attribute. Edit mode tests run in the EditorApplication.update callback loop. You can't run coroutines in Edit mode tests.
[UnityTest]You can also control entering and exiting Play mode from an Edit mode test, allowing your test to make changes before entering Play mode.
Edit mode tests must have an assembly definition that references and have the Editor as their only target platform:
nunit.framework.dllassembly "includePlatforms": [ "Editor" ],
Play mode tests
You can run Play mode tests in a Player or inside the Editor. Play mode tests allow you to test your runtime application code, and the tests run as coroutines if marked with the attribute.
[UnityTest]Play mode tests must fulfill the following conditions:
- Tests must have their own assembly definition with a reference to .
nunit.framework.dll - Test scripts must be in a folder alongside the .asmdef file.
- The test assembly must reference any additional assemblies containing code you want to test.
assembly "references": [ "NewAssembly" ], "optionalUnityReferences": [ "TestAssemblies" ], "includePlatforms": [],
Recommendations
Use the NUnit attribute instead of the unless:
[Test][UnityTest]- You need to yield instructions for the Editor in Edit mode tests
- You need to skip a frame or wait for a certain amount of time in Play mode tests.