Unit testing

I have a question about the statement that we don’t often unit test games. Since I started following the gamedev courses I was wondering why there is no mention of unit tests. Could you elaborate a bit on the reason why unit tests are not often used in game development? I find that it will probably be very handy for complicated projects like the RPG course for example with so many interconnected systems plus I find that thinking about whether the code is easily testable often results in a better and cleaner code.

I will soon start creating my own games and this was 1 topic that I was gonna look at, but might as well get some insight on this forum.

Should I start without unit tests and only look at it only once my project reaches a certain complexity state? Is there any recommendation in game development about this?

1 Like

Unit testing is something that is often overlooked by Indie game developers, but does become more important with larger scale game companies. Unfortunately, we don’t currently have any courses covering unit testing, but this might make a good suggestion for a future course.

Ideally, if you are using unit testing, it’s better to begin testing as soon as possible in the development cycle. Start with the test conditions…
For example:
Suppose I have a health component that I want to ensure that the health points are properly updated after the character has taken damage, that negative damage is ignored, and that the health points never go below 0, and that when the health has reached zero, the character dies.

So these are our tests.

  • Character’s health points drop when damage is taken
  • Negative damage is ignored
  • health points never drop below zero
  • When the health reaches zero, the character dies.

Each of these conditions will be an individual test, testing one “unit” of the method. For example, your first test would simply call TakeDamage with -10 points and see if the health is lower.
You’ll keep writing and refactoring your code, then testing until all of these tests pass.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms