Getting Started with the Unity Test Runner

Sindhu Rathod
XRPractices
Published in
2 min readJan 23, 2020

To write tests, you first need to know about Unity’s Test Runner. The Test Runner lets you run tests and see if they pass. It is the unit testing feature provided by Unity .

To open the Unity Test Runner, choose Window ▸ General ▸ Test Runner.

Once the test runner window is opened, you can drag it next to your Scene window to make your life simple :P

There are two types of modes as you can see in the window. EditMode and PlayMode tests. Edit mode tests are pretty much exactly the same as any unit tests that you would write for any other framework ; similar to spock. Playmode tests are integrated in play state of the game, say you want to test parameters change for next 5 seconds of frame when the game is on play.

Open EditMode tab and click on Create Editmode Test Assembly Folder.This creates a folder called Tests and Tests.asdmef in project.Tests.asdmef is an assembly defination , a json file which unity compiles separate assembly from all the scripts in that folder.

To ensure your test code has access to the all game class scripts, you need to create an assembly of your game (all that has to be tested in Scripts/) and set the reference in the Tests assembly.By doing this, unity will start to compile this assembly seperately from the settings. Lets write unit test for each and every single file in application residing in scripts folder. Go to Scripts folder, right-click and choose Create ▸ Assembly Definition and name it as Application

Now open Tests assembly file and provide the linking for the application by adding Application into assembly Definition References.

Unity Version 2018.3.9f1
Unity Version 2019.3.0f6

We are done with the Test Runner setUp .

--

--

Sindhu Rathod
XRPractices

ThoughtWorker! Introverts soul trapped in extroverts body.