Install Understudy
Requirements
Understudy has the following requirements:
- Unity 6.0 or later.
- The Test Framework package (
com.unity.test-framework), which Unity installs in new projects. - The Mono Cecil package (
com.unity.nuget.mono-cecil) 1.10 or later. Understudy's compilation step uses it to rewrite the code under test. Importing Understudy installs it if your project doesn't have it.
Spies, stubs and fakes work in tests the Editor runs, and in Play mode tests the Test Runner builds into a player. The game you release is unchanged: a player build without tests is never woven and contains none of Understudy. For more information, refer to Player builds.
The Input System package (com.unity.inputsystem) is optional. When it is installed, leak detection also
covers its devices and sensors. For more information, refer to Members Understudy
declares non-deterministic.
Install the package
To install Understudy, perform the following steps:
- Go to Window > Package Manager.
- Select My Assets, then select Understudy.
- If the package isn't downloaded yet, select Download.
- Select Import.
- In the Import Unity Package window, select Import.
When the import finishes and your scripts recompile, Understudy is active.
If the Console window shows an error that starts with Understudy: nothing is woven and names the
Mono Cecil package, the package is missing or older than 1.10, for example because it was cleared in the
Import Unity Package window. To install or update it, perform the following steps:
- Go to Window > Package Manager.
- Select + > Install package by name.
- Enter
com.unity.nuget.mono-cecil, then select Install.
Update Understudy
To update Understudy to a new version, perform the following steps:
- Delete the
Assets/Understudyfolder, so that no file the new version removed stays behind. - Import the new version, as in Install the package.
Between the two steps, the Console window shows compile errors for the tests that use Understudy. They clear once the import finishes.
Your settings are in ProjectSettings/Understudy.json, outside the package folder, so they stay as they
are.
Remove Understudy
To remove Understudy from your project, perform the following steps:
- Delete the tests that use Understudy, or remove
Understudyfrom the Assembly Definition References of their test assemblies and delete the code that uses it. - Delete the
Assets/Understudyfolder. Unity recompiles every script, without weaving. - Optionally, delete
ProjectSettings/Understudy.json.
The Mono Cecil package stays installed, since other packages can depend on it.
Understudy menus
Understudy adds the following menu items to the Unity Editor:
| Menu item | Description |
|---|---|
| Tools > Understudy > Settings | Opens the Understudy page of the Project Settings window. For more information, refer to Project Settings reference. |
| Tools > Understudy > Quick Usage Guide | Opens the Quick Usage Guide. |
| Tools > Understudy > User Manual | Opens the User Manual. |
| Tools > Understudy > Public API | Opens the Public API reference. |
Package contents
Understudy installs into Assets/Understudy as C# source, so it is committed with your project. The
folder contains the following:
| Folder | Contents |
|---|---|
Runtime | Spies, stubs, fakes and leak detection, and the code analysis that checks your tests as you write them. |
Runtime/Input System | The Input System members leak detection covers. Compiles only when the Input System package is installed. |
CodeGen | The compilation step that rewrites the code under test in the Editor. |
Editor | The Understudy page of the Project Settings window, and the checks that guard player builds. |
Tests | Understudy's own tests, which don't compile in your project. |
Documentation | The Quick Usage Guide, the User Manual, and the Public API reference. |