To create a test, do the following:
Now you’ll see two sample tests in the Test Runner window:
Now you can open the tests in your favorite script editor.
You can also create test scripts by navigating to Assets > Create > Testing > C# Test Script, unless adding a test script would result in a compilation error.
Note: Unity does not include
TestAssemblies
(NUnit, Unity Test Framework, and user script assemblies) when using the normal build pipeline, but does include them when using Run on <Platform> in the Test Runner window.
To create another set of tests:
The assembly definition is assigned the same name as your new asset. To rename it, change the Name in the Insepctor window. Assembly definition names must be unique.
Note: Changing the file name of the assembly definition file does not affect the value of the Name property in the file. Use the Inspector window to make sure the name is properly changed.
By default Any Platform is preselected as the target platform for the new assembly, which means the test script appears as a PlayMode test in the TestRunner window. To change it to an EditMode test, in the Inspector window select Editor only under Platforms.
New assemblies created through the Assets menu should automatically include references to UnityEngine.TestRunner
and UnityEditor.TestRunner
. If these references are missing, add them in the Inspector window under Assembly Definition References:
If you have a lot of tests, and you only want to view/run a sub-set of them, you can filter them in three ways (see image above):
Type in the search box in the top left
Click a test class or fixture (such as NewTestScript in the image above)
Click one of the test result icon buttons in the top right
For more information, see Edit Mode vs. Play Mode tests.