Skip to main content

Run tests from the command line

Invoke-UnityTests.ps1 on Windows and run_unity_tests.sh on Linux run the tests of a Unity project from the command line and print only what needs your attention: the tests that didn't pass, with their messages, and a count of the rest. They're generic scripts, independent of the kit: copy one into any Unity project to use it there, whether or not that project has the kit.

Steps​

  1. Get the script: Scripts~/Invoke-UnityTests.ps1 in the kit repository. If you installed the kit through the Creator Companion, it's also in Packages/com.tsvrc.udon-test-kit/Scripts~. A .unitypackage can't carry it.

  2. Copy it into your project, such as its root folder. It finds the project by looking up from its own folder.

  3. Close the Unity Editor. Batch mode can't open a project another Editor has open.

  4. Run it from that folder, in PowerShell:

    .\Invoke-UnityTests.ps1

If PowerShell refuses to run the script because of its execution policy, allow local scripts once with Set-ExecutionPolicy -Scope CurrentUser RemoteSigned.

Each script runs the Edit Mode tests of your project, then its Play Mode tests, each mode in its own batch-mode Unity process, and exits with 1 when a test failed or was inconclusive, or a run didn't finish. That makes either one usable as a build step as it is.

Run part of the tests​

By default, each script runs the tests in every assembly definition under Assets and in scripts without one, and leaves out the tests that come with packages. To run one mode:

.\Invoke-UnityTests.ps1 -TestMode PlayMode

To run particular test assemblies, separated with ;:

.\Invoke-UnityTests.ps1 -AssemblyNames "MyWorld.Tests.EditMode;MyWorld.Tests.PlayMode"

The reference pages list every option, including where each script looks for Unity, where it writes results, and how it passes other arguments to Unity.