Creating and executing a unit test in PlayMode
It’s a good idea to write as much of the logic for a game as isolated, non-MonoBehaviour classes that are easy to unit test in EditMode as possible.
However, some of the logic in a game relates to things that happen when the game is running. Examples include physics, collisions, and timing-based events. We test these parts of our games in PlayMode.
In this recipe, we’ll create one very simple PlayMode test to check that the physics affect a Rigidbody (based on an example from the Unity documentation):
Figure 19.16: Running a physics PlayMode test
How to do it...
To create and execute a unit test in PlayMode, follow these steps:
- Create a new 3D Unity project.
- Display the Test Runner panel by going to Window | General | Test Runner.
- Ensure that the PlayMode button is selected in the Test Runner panel.
- In the Test Runner panel, click the Create PlayMode Test Assembly Folder...