Jump to content
  • Advertisement
  • entries
  • comments
  • views

Not fun but good.

Sign in to follow this  
Mike Bossy


Mushu is right that a lot of people find unit tests annoying. Mostly because it seems like a waste of time to test something that hopefully already works. This is the case when you go back and write unit tests for old code. The point is that even if your test doesn't find bugs now it might in the future. With regular refactoring becoming the norm and not the exception tests you write now will live with your code forever.

Looking to the future isn't the only plus of writing unit tests for old code. This afternoon I was finishing up unit tests on my animation class and I found a nice bug around trying to load corrupt animations. I never ran into the bug while coding my last game but this is the type of bug that you can hit in the future and spend hours trying to debug.

I also finished refactoring my manager classes to accept a mutex object in the constructor instead of creating platform specific manager classes. Once again I had tests ready to go after my refactoring was done that I could run to make sure I hadn't messed something up by accident.

I should also clarify that you don't really need to follow pure test driven methods where you create the test before you create the object. A lot of people find that technique ideal but I think you still gain a lot by having unit tests after the fact.
Sign in to follow this  

1 Comment

Recommended Comments

Hi Mike,

Thanks a lot for writing about the unit tests - I had never been exposed to them before, and it is an interesting method of verification. I have a couple of questions though:

1. Is the test supposed to look for exceptional cases or should it be testing functionality of the class?

2. How detailed should the test be? I have a CEntity class which is the base class for all game objects which literally has about one hundred methods (implying lots of functionality). How in the world do you devise one hundred or more tests for a single class?

I suppose part of this will come with experience in testing, but I have over 200 classes in my project - it just seems mind boggling that this type of testing gets added to libraries after the fact.

Anyways, thanks again for the post. Have you considered writing a short article for gamedev on the topic? I think software engineering is a field that is under represented by the current set of articles. Give it some thought...

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!