Version: Unity 6.2 (6000.2)
Language : English
Get started with Unity Test Framework
Create a test assembly

Edit mode and Play mode tests

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 UnityEditor and UnityEngine namespaces.

With Edit mode tests you can test any of your Editor extensions using the [UnityTest] attribute. Edit mode tests run in the EditorApplication.update callback loop. You can’t run coroutines in Edit mode tests.

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 nunit.framework.dll and have the Editor as their only target platform:

assembly
    "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 [UnityTest] attribute.

Play mode tests must fulfill the following conditions:

  • Tests must have their own assembly definition with a reference to nunit.framework.dll.
  • Test scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
    See in Glossary
    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": [],

Note: Your test assembly can’t reference the predefined Assembly-Csharp.dll assembly. You must move code you want to test into a custom assembly that your test assembly references. For more information, refer to Creating assembly assets.

Recommendations

Use the NUnit [Test] attribute instead of the [UnityTest] unless:

Additional resources

Get started with Unity Test Framework
Create a test assembly