itch.io is community of indie game creators and players

Devlogs

​Test Driven Development Series Episode I: A New Hope

Lords of Illic
A browser Lords of Illic made in HTML5

Since I have started this blog, I think I should start with the most important thing that I have come across when working on Lords of Illic:

Test driven development.

It is on its own line to accentuate how important it is.

Embracing test-driven development has helped me improve both the quality and consistency of the code I produce. Perhaps more importantly, it has made me more confident of my code once it is produced and better able to adapt my code base to inevitable requirements changes.

Recently I watched a video on Dave Farely’s Continuous Delivery Channel in which he was talking to Kent Beck, the re-discoverer of test driven development. I think Kent summed up the benefits of test driven development very well in this comment:

“It is an anxiety reducing technique, which is what is most important to me - it has fewer side effects than all the chemicals you can ingest.”

(If you are curious, search “Did Kent Beck REALLY Invent TDD? | Kent Talks About TDD, TCR & Reveals One Of His BEST Ideas”, I’d put a link but I don’t want to imbed the video)

Ever since I played my first video game I have wanted to make my own. I have gone from drawing Legend of Zelda levels on paper to having a prototype video game. I first decided I wanted to make a turn-based strategy game in 2018, but didn’t create the repository and start working in unity until 2019. It is now 2023, so it has been about 5 years. I have learnt a lot about making games, programming and working on creative projects. If there is one thing that has come up time and time again it is how do I manage stress and anxiety? I have poured a lot of time into Lords of Illic and I am understandably very invested in the game. I have always sought quality and best practice in every aspect of development; whether that is the code that I write, the scenes that I edit or the art that I produce for the game. I am always striving for improvement and yet... 

How much time have I spent pulling out my hair (literally, it is a big problem) because as I try to get the game ready to play I have found bugs that lead to bugs that lead to bugs. I have spent months like this. I kind of imagine it like one big steampunk machine with a massive array of gears, dials and levers. 

You realign one part of the system and you can hear that somewhere another gear has not just popped out of alignment but has been thrown out of the machine and under the couch. As you run to get the piece you can hear the machine groaning as gears grind in absolute chaos. So you start to run around everywhere trying to fix everything. All I could do as I did was think of Alice in Wonderland:

“Now, here, you see, it takes all the running you can do, to keep in the same place. If you want to get somewhere else, you must run at least twice as fast as that!”

It is enough to make you want to scream.

Did I give up?

No.

Did I think of giving up?

No.

I will admit that I did sulk for a while and worked on getting all the achievements in Elden Ring but I digress.

Now you might have guessed what the solution was - Test Driven Development. Of course there is no silver bullet. In fact I will admit that switching to Test Driven Development can be stressful in its own way and it doesn’t make all the bugs magically vanish but…

Wouldn’t it be nice if there was a way for you to know when you have created a bug? Wouldn’t it be even better if you knew where?

It turns out that you can. 

It isn’t all that difficult really. 

All of which sounds too good to be true but it is all really simple.

Tests are well tests… They test things. Like if I add an item to my inventory has it been added? That might sound a bit simplistic but… How many times have you accidentally written the wrong if statement? The wrong variable name? Just meant to write that line of code but didn’t actually do it? A simple test means that in less than a second you know whether or not you can do a simple thing. Now what if you had tests for each simple thing that you can do in your game. Then in a couple of seconds you could run all your tests and know that either you can do every simple thing or you can’t. Furthermore, when you can’t do something, you know what it is. 

Unless you don’t have a test for it. (Which is the problem you face when switching over, a topic I will tackle in a different post).

But believe it or not, test driven development is just a way to have tests for that. You write a test and then make the code pass it. Then if you think of a better way to do it you do some refactoring. Run the test and if it passes you know you have actually made things better. If you haven’t you can just undo the changes.

Then you write the next test and get your code to pass it. At every step you run your tests and you know where you are at. They say ignorance is bliss but… really you just want to build your game and show people how cool it is right?

So when I have found that when you have a problem like this you have to take a deep breath. Write a test and remember:

Real life isn’t Wonderland, you can’t run twice as fast.

Download Lords of Illic
Leave a comment