Saturday, December 09, 2006

Why Test Suites Are Mandatory

I am not the original developer on Fall of Rome. From my perspective, much of the application is Legacy Code (Affiliate). During the Team Game Launch, I fell fell victim to the lack of unit tests around many parts of the game.

There is a method in the game that returns all orders for any Actor - emissaries, agents, and pop centers are included. This method had a bug. Instead of using the equals() method to determine if the actor executing the order was the same, it used the == operator, which requires the actor to be the exact same instance. This doesn't work if the actor has been recreated, and you are now trying to find out what orders it issued.

After fixing this bug, I ran all the tests I have written, and everything worked well. Unfortunately, several of the game orders did not. There was validation code in place that checked to see if the actor issuing the order had done anything else that turn (train military leaders, build a temple, etc). Once I fixed the getMyOrders() method, it started failing all the validations (the vallidations were written to work with the broken code). This caused no end of difficulties for players who discovered these bugs.

Two lessons learned here:
1) Programmer tests are mandatory - with a test suite in place this bug would not have occured.
2) Be very careful when "fixing" legacy code.

I've learned both of these lessons before - it's a shame to have to relearn them like this.

1 Comments:

At 10:22 AM, Blogger Rick McDowell said...

What is the test suite? Is it an application, or is it more code written by the developer?

 

Post a Comment

<< Home