How to setup your project for Unit Testing

The first step to testing your game is setting up the project for unit tests. Watch this Unity tutorial to learn how!

Disclaimer - This is just ONE way to set up tests. If you have an alternative flow or structure please feel free to let everyone know in the comments

TL;DW

  • Right-Click in Project Panel, expand the Create → Testing menu, and click on “Test Assembly Folder”.
  • Rename the new folder to “PlayMode”.
  • Create a new folder called “Tests” inside of the “Assets” folder.
  • Drag the “PlayMode” folder into the “Tests” folder.
  • Rename the Assembly Definition File inside of the “PlayMode” folder to “PlayModeTests”.
  • Open “PlayModeTests.asmdef” in the inspector, rename it to “PlayModeTests”, and click Apply.
  • Navigate to the top navigation menu, expand Window → General, and click on “Test Runner”.
  • Dock the Test Runner window to your editor.
  • Click on the “Assets” folder in the Project panel.
  • Click on “EditMode” in the Test Runner Panel and then click on the “Create Test Script in current folder” button.
  • Drag the new folder into the “Tests” folder.
  • Rename the new folder to “EditMode”.
  • Rename the Assembly Definition File inside of the “EditMode” folder to “EditModeTests”.
  • Open “EditModeTests.asmdef” in the inspector, rename it to “EditModeTests”, and click Apply.
2 Likes

You can just name the files/folders correctly the first name round. That would remove a lot of these steps. Otherwise, a good guide.