For data-driven testing, you may want to have your tests parameterized. You may use both the [NUnit](http://www.nunit.org/) attributes [TestCase](https://github.com/nunit/docs/wiki/TestCase-Attribute) and [ValueSource](https://github.com/nunit/docs/wiki/ValueSource-Attribute) with a unit test.
> **Note**: With `UnityTest` it is recommended to use `ValueSource` since `TestCase` is not supported.
For data-driven testing, you may want to have your tests parameterized. You may use both the [NUnit](http://www.nunit.org/) attributes [TestCase](https://github.com/nunit/docs/wiki/TestCase-Attribute) and [ValueSource](https://github.com/nunit/docs/wiki/ValueSource-Attribute) with a unit test.
> **Note**: With `UnityTest` it is recommended to use `ValueSource` since `TestCase` is not supported.
`WaitForDomainReload` is an [IEditModeTestYieldInstruction](./reference-custom-yield-instructions.md) that you can yield in Edit Mode tests. It delays the execution of scripts until after an incoming domain reload. If the domain reload results in a script compilation failure, then it throws an exception.
| `WaitForDomainReload()` | Create a new instance of the `WaitForDomainReload` yield instruction. |
## Example
``` C@
[UnitySetUp]
public IEnumerator SetUp()
{
File.Copy("Resources/MyDll.dll", @"Assets/MyDll.dll", true); // Trigger a domain reload.
AssetDatabase.Refresh();
yield return new WaitForDomainReload();
}
# WaitForDomainReload
`WaitForDomainReload` is an [IEditModeTestYieldInstruction](./reference-custom-yield-instructions.md) that you can yield in Edit Mode tests. It delays the execution of scripts until after an incoming domain reload. If the domain reload results in a script compilation failure, then it throws an exception.
Here you can find other related resources to the Unity Test Framework:
*[Performance Benchmarking in Unity: How to Get Started](https://blogs.unity3d.com/2018/09/25/performance-benchmarking-in-unity-how-to-get-started/)[Blog]
# Resources
Here you can find other related resources to the Unity Test Framework:
*[Performance Benchmarking in Unity: How to Get Started](https://blogs.unity3d.com/2018/09/25/performance-benchmarking-in-unity-how-to-get-started/)[Blog]
*[Testing Test-Driven Development with the Unity Test Runner](https://blogs.unity3d.com/2018/11/02/testing-test-driven-development-with-the-unity-test-runner/)[Blog]
To create a **Play Mode** test, you can follow a similar process as when you want to create an **Edit Mode** test.
1. Start with switching to the **PlayMode** tab in the **Test Runner** window.
2. Create a test assembly folder (see [How to create a new test assembly)](./workflow-create-test-assembly.md). The folder name is *Tests* by default (or *Tests 1*, *Tests 2*, etc. if the preceding name is already in use).
![PlayMode tab](./images/playmode-tab.png)
> **Note**: If you don’t see the **Create Play Mode Test Assembly Folder** button enabled, make sure that in the Project window you navigate out of a folder with another .asmdef (such as one for Edit Mode tests).
3. When you have your Play Mode test assembly folder ready, then [create your Play Mode test](./workflow-create-test.md).
> **Note**: [Pre-defined Unity assemblies](https://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html) (such as _Assembly-CSharp.dll_) do not reference your new assembly.
## References and builds
Unity Test Framework adds a reference to `TestAssemblies` in the [Assembly Definition](https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html) file, but it won't include any other references (e.g., to other scripting assemblies within the Unity project). So you need to add other assemblies yourself if you want to test them too.
Unity does not include `TestAssemblies` in Player builds, but in the Test Runner window, we have such an option. If you need to test code in pre-defined assemblies, you can reference `TestAssemblies` from other assemblies. You must remove these tests after the test run so that Unity does not add them to the final Player build.
To do this, in the Test Runner window choose **Enable playmode tests for all assemblies** option from the drop-down menu (to expand, click on the small list item in the top right corner). In the dialog box, click **OK** to manually restart the Editor.
![Enable Play Mode tests for all assemblies](./images/playmode-enable-all.png)
> **Note**: **Enabling Play Mode tests for all assemblies** includes additional assemblies in your project build, which can increase the project’s size as well as the build time.
# Workflow: How to create a Play Mode test
To create a **Play Mode** test, you can follow a similar process as when you want to create an **Edit Mode** test.
1. Start with switching to the **PlayMode** tab in the **Test Runner** window.
2. Create a test assembly folder (see [How to create a new test assembly)](./workflow-create-test-assembly.md). The folder name is *Tests* by default (or *Tests 1*, *Tests 2*, etc. if the preceding name is already in use).
![PlayMode tab](./images/playmode-tab.png)
> **Note**: If you don’t see the **Create Play Mode Test Assembly Folder** button enabled, make sure that in the Project window you navigate out of a folder with another .asmdef (such as one for Edit Mode tests).
3. When you have your Play Mode test assembly folder ready, then [create your Play Mode test](./workflow-create-test.md).
> **Note**: [Pre-defined Unity assemblies](https://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html) (such as _Assembly-CSharp.dll_) do not reference your new assembly.
## References and builds
Unity Test Framework adds a reference to `TestAssemblies` in the [Assembly Definition](https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html) file, but it won't include any other references (e.g., to other scripting assemblies within the Unity project). So you need to add other assemblies yourself if you want to test them too.
Unity does not include `TestAssemblies` in Player builds, but in the Test Runner window, we have such an option. If you need to test code in pre-defined assemblies, you can reference `TestAssemblies` from other assemblies. You must remove these tests after the test run so that Unity does not add them to the final Player build.
To do this, in the Test Runner window choose **Enable playmode tests for all assemblies** option from the drop-down menu (to expand, click on the small list item in the top right corner). In the dialog box, click **OK** to manually restart the Editor.
![Enable Play Mode tests for all assemblies](./images/playmode-enable-all.png)
> **Note**: **Enabling Play Mode tests for all assemblies** includes additional assemblies in your project build, which can increase the project’s size as well as the build time.
For more information, see [Edit Mode vs. Play Mode tests](./edit-mode-vs-play-mode-tests.md).
Unity Test Framework looks for a test inside any assembly that references [NUnit](http://www.nunit.org/). We refer to such assemblies as `TestAssemblies`. The [Test Runner](./getting-started.md) UI can help you set up `TestAssemblies`. **Play Mode** and **Edit Mode** tests need to be in separate assemblies.
In the **Test Runner** window, you will see an **EditMode** tab enabled by default, as well as a **Create EditMode Test Assembly Folder** button.
Click the button to create a *Tests* folder with a respective .asmdef file by default. Change the name of the new [Assembly Definition](https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html), if necessary, and press Enter to accept it.
![New Test folder and assembly file](./images/tests-folder-assembly.png)
In the Inspector window, it should have references to **nunit.framework.dll***,***UnityEngine.TestRunner,** and **UnityEditor.TestRunner** assemblies, as well as **Editor** preselected as a target platform.
> **Note**: The **UnityEditor.TestRunner** reference is only available for [Edit Mode tests](./edit-mode-vs-play-mode-tests.md#edit-mode-tests).
Unity Test Framework looks for a test inside any assembly that references [NUnit](http://www.nunit.org/). We refer to such assemblies as `TestAssemblies`. The [Test Runner](./getting-started.md) UI can help you set up `TestAssemblies`. **Play Mode** and **Edit Mode** tests need to be in separate assemblies.
In the **Test Runner** window, you will see an **EditMode** tab enabled by default, as well as a **Create EditMode Test Assembly Folder** button.
Click the button to create a *Tests* folder with a respective .asmdef file by default. Change the name of the new [Assembly Definition](https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html), if necessary, and press Enter to accept it.
![New Test folder and assembly file](./images/tests-folder-assembly.png)
In the Inspector window, it should have references to **nunit.framework.dll***,***UnityEngine.TestRunner,** and **UnityEditor.TestRunner** assemblies, as well as **Editor** preselected as a target platform.
> **Note**: The **UnityEditor.TestRunner** reference is only available for [Edit Mode tests](./edit-mode-vs-play-mode-tests.md#edit-mode-tests).
1. Create your *Test*[assembly folder](./workflow-create-test-assembly.md) and select it in the **Project** window.
2. Click the button **Create Test Script in current folder** option in the **Test Runner** window.
![EditMode create test script](./images/editmode-create-test-script.png)
3. It creates a *NewTestScript.cs* file in the *Tests* folder. Change the name of the script, if necessary, and press Enter to accept it.
![NewTestScript.cs](./images/new-test-script.png)
Now you’ll see two sample tests in the Test Runner window:
![Test templates](./images/test-templates.png)
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](http://www.nunit.org/), 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.
## Filters
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](./edit-mode-vs-play-mode-tests.md).
# Workflow: How to create a test
To create a test, do the following:
1. Create your *Test*[assembly folder](./workflow-create-test-assembly.md) and select it in the **Project** window.
2. Click the button **Create Test Script in current folder** option in the **Test Runner** window.
![EditMode create test script](./images/editmode-create-test-script.png)
3. It creates a *NewTestScript.cs* file in the *Tests* folder. Change the name of the script, if necessary, and press Enter to accept it.
![NewTestScript.cs](./images/new-test-script.png)
Now you’ll see two sample tests in the Test Runner window:
![Test templates](./images/test-templates.png)
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](http://www.nunit.org/), 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.
## Filters
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](./edit-mode-vs-play-mode-tests.md).
If you run a **Play Mode** test in the same way as an [Editor test](./workflow-run-test.md), it runs inside the Unity Editor. You can also run Play Mode tests on specific platforms. Click **Run all in the player** to build and run your tests on the currently active target platform.
![Run PlayMode test in player](./images/playmode-run-standalone.png)
> **Note**: Your current platform displays in brackets on the button. For example, in the image above, the button reads **Run all in player (StandaloneWindows)**, because the current platform is Windows. The target platform is always the current Platform selected in [Build Settings](https://docs.unity3d.com/Manual/BuildSettings.html) (menu: **File** > **Build Settings**).
The test result displays in the build once the test completes:
![Results of PlayMode in player test run](./images/playmode-results-standalone.png)
The application running on the platform reports back the test results to the Editor UI then displays the executed tests and shuts down. To make sure you receive the test results from the Player on your target platform back into the Editor that’s running the test, both should be on the same network.
> **Note:** Some platforms do not support shutting down the application with `Application.Quit`, so it will continue running after reporting the test results.
If Unity cannot instantiate the connection, you can see the tests succeed in the running application. Running tests on platforms with arguments, in this state, does not provide XML test results.
# Workflow: How to run a Play Mode test in player
If you run a **Play Mode** test in the same way as an [Editor test](./workflow-run-test.md), it runs inside the Unity Editor. You can also run Play Mode tests on specific platforms. Click **Run all in the player** to build and run your tests on the currently active target platform.
![Run PlayMode test in player](./images/playmode-run-standalone.png)
> **Note**: Your current platform displays in brackets on the button. For example, in the image above, the button reads **Run all in player (StandaloneWindows)**, because the current platform is Windows. The target platform is always the current Platform selected in [Build Settings](https://docs.unity3d.com/Manual/BuildSettings.html) (menu: **File** > **Build Settings**).
The test result displays in the build once the test completes:
![Results of PlayMode in player test run](./images/playmode-results-standalone.png)
The application running on the platform reports back the test results to the Editor UI then displays the executed tests and shuts down. To make sure you receive the test results from the Player on your target platform back into the Editor that’s running the test, both should be on the same network.
> **Note:** Some platforms do not support shutting down the application with `Application.Quit`, so it will continue running after reporting the test results.
If Unity cannot instantiate the connection, you can see the tests succeed in the running application. Running tests on platforms with arguments, in this state, does not provide XML test results.
For more information, see [Edit Mode vs Play Mode tests](./edit-mode-vs-play-mode-tests.md).
To run a test, you need to double-click on the test or test fixture name in the **Test Runner** window.
You can also use one of the buttons on the top bar, **Run All** or **Run Selected**. As a result, you’ll see the test status icon changed and a counter in the top right corner updated:
![EditMode Run Test](./images/editmode-run-test.png)
You may also use a context menu option **Run**, right-click on any item in the test tree to have it (with all its children if any) run.
![EditMode Run Tests](./images/editmode-run-tests.png)
## Run tests within Rider
It is possible to run unit tests in the Unity Test Framework directly from [JetBrains Rider](https://www.jetbrains.com/rider/).
# Workflow: How to run a test
To run a test, you need to double-click on the test or test fixture name in the **Test Runner** window.
You can also use one of the buttons on the top bar, **Run All** or **Run Selected**. As a result, you’ll see the test status icon changed and a counter in the top right corner updated:
![EditMode Run Test](./images/editmode-run-test.png)
You may also use a context menu option **Run**, right-click on any item in the test tree to have it (with all its children if any) run.
![EditMode Run Tests](./images/editmode-run-tests.png)
## Run tests within Rider
It is possible to run unit tests in the Unity Test Framework directly from [JetBrains Rider](https://www.jetbrains.com/rider/).
For more information, see the [JetBrains official documentation](https://www.jetbrains.com/help/rider/Running_and_Debugging_Unity_Tests.html) and their blog post [Run Unity tests in Rider 2018.1](https://blog.jetbrains.com/dotnet/2018/04/18/run-unity-tests-rider-2018-1/).
Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.
Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.