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
- Windows
- Linux
-
Get the script:
Scripts~/Invoke-UnityTests.ps1in the kit repository. If you installed the kit through the Creator Companion, it's also inPackages/com.tsvrc.udon-test-kit/Scripts~. A.unitypackagecan't carry it. -
Copy it into your project, such as its root folder. It finds the project by looking up from its own folder.
-
Close the Unity Editor. Batch mode can't open a project another Editor has open.
-
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.
-
Get the script:
Scripts~/run_unity_tests.shin the kit repository, or inPackages/com.tsvrc.udon-test-kit/Scripts~of a project that has the kit installed as a package. A.unitypackagecan't carry it. -
Copy it into your project, such as its root folder, and make the copy executable with
chmod +x run_unity_tests.sh. It finds the project by looking up from its own folder. -
Close the Unity Editor. Batch mode can't open a project another Editor has open.
-
Run it from that folder, in Bash, with the Windows build target:
./run_unity_tests.sh -- -buildTarget win64
The kit needs the Windows build target on Linux. Everything after -- goes to Unity, and in batch
mode, Unity opens a project it hasn't imported yet on the Linux build target unless
-buildTarget says otherwise.
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:
- Windows
- Linux
.\Invoke-UnityTests.ps1 -TestMode PlayMode
./run_unity_tests.sh --test-mode PlayMode -- -buildTarget win64
To run particular test assemblies, separated with ;:
- Windows
- Linux
.\Invoke-UnityTests.ps1 -AssemblyNames "MyWorld.Tests.EditMode;MyWorld.Tests.PlayMode"
./run_unity_tests.sh --assembly-names "MyWorld.Tests.EditMode;MyWorld.Tests.PlayMode" -- -buildTarget win64
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.