Monday 12 July 2010

Tests on Android

Last night I added unit test to my the android game I am developing. This is quite a step for me. While I make up of unit tests when possible it is something I have not done on a android project until now.

It is funny given I am addicted to them on other platforms, perhaps one of the reasons for not using them on android is none of the work has reached a complectixty that I felt needed unit tests. I can hear some TDD expert reaching for a large axe in order to take out this programmer.

I will say it to irritate the TDD gods, for small projects that have a definite limited scope writing unit tests slows me down. I can hold the complexity in my head and reaaching the ideal code structure is not important. Abstractions leak happen, things are not quite where they should be and sometime state is repeated in places. For code programs less then say 2K lines of Java, for me, it is not a big deal and writing tests always feels like an overkill and a waste of time.

That is just what I have experienced and this is particularly true in in simple games where you have to play the game so much to balance it you naturally do a lot of testing.

Now for apps or code I expect to work on for an extended period I tend to write tests. I also attempt to write the tests first in many cases as I find it helps to clarify my thoughts.

Another really important bonus of test is I can safely work on code while tired. When I am tired separating what is meant to be happening and writing that in a test then making the code do that saves me a lot of headaches. How many times have you returned to some code you hacked out late one night and asked yourself what was I thinking?

I suppose I do wonder why the games industry has not taken on TDD or at least comprehensive unit tests with more vigor. Their code is very complex and the industry traditionally works its staff pretty hard and so a lot of code is hasked out late at night. They seem like the ideal candidate for these processes. From a few of the friends I still retain from my stint in that industry it does appear that they are heading that way but it is sort of after nearly everyone else has made progress in that direction.

No comments:

Post a Comment