Introduction To Unity Unit Testing

Learn all about the Unity Test Framework and how to set up Unit Tests in your Unity projects. By Ben MacKinnon.

5 (1) · 1 Review

Download materials
Save for later
Share
You are currently viewing page 5 of 5 of this article. Click here to view the first page.

Where to Go From Here?

Download the completed project files by clicking the Download Materials link at the top or bottom of the tutorial.

You covered a lot of ground here. In this tutorial, you learned what unit tests are and how to write them in Unity. You also wrote six unit tests that all passed successfully and learned some of the pros and cons of unit testing.

Feeling confident? There are plenty more tests you could write. Try looking at all the game class files and writing unit tests for other parts of the code. Consider adding tests for the following scenarios:

  • Moving left and right works correctly for the ship.
  • Not only testing how the ship moves, but also that it stays within limits.
  • Starting a new game sets the score to 0.
  • An asteroid that moves off the bottom of the screen should be destroyed.

If you’re interested in taking your unit testing to the next level, look into dependency injection and mocking frameworks. This can make it a lot easier to configure your tests.

Also, read through the NUnit documentation to learn more about the NUnit framework.

We hope you enjoyed this tutorial. If you have any questions or comments, please join the forum discussion below!