This post talks about an old, dead project, SprayFire; you can read about it's demise. All links pointing to the project have been removed.

A little over a year and a half ago I started working on the SprayFire project and Test Driven Development. At the time I started with unit testing I really wasn’t sure what the benefits, if any, would be. Now having had time spent writing a decent sized codebase and many unit tests the benefits are obvious and numerous.

Below are some of the primary reason I like to unit test my personal projects and why you might find success in unit testing as well.

I’m confident in my codebase

Without tests developers live in a persistent state of worry and fear. Is this commit going to break something? Does this commit even satisfy the requirements of the project? Without unit tests it is hard to answer these questions when you develop new features. Without unit tests it is increasingly harder to answer these questions 6 months down the road when half of your development team has added to the project and refactored your code.

However with unit tests I am confident in my ability to adapt the codebase to changes. I’m confident that I can make those changes and not break other parts of the system. If I do break other parts of the system I have a warning before anything bad happens in a production environment. This makes me worry less about committing code or making changes because I have visual, undeniable proof of my work.

it makes me think about what I’m coding

A TDD myth is that by practicing this type of development you get a modular, well structured, clean system regurgitated out of the other end of the process. Unfortunately, that’s not really how it works. Writing unit tests and TDD are not magical processes that make your design instantly great.

Thought, effort and research still have to go into the designs of your codebases. TDD helps force you think about the design up front before you write any code. You can think of your unit tests as the very first app utilizing your code base. If, while creating this initial app, you find that it is hard or clumsy to write the tests then your actual users will have a hard or clumsy time using your code.

it makes you feel good and is fun!

No, seriously. Writing unit tests really is a lot of fun and you’ll feel better having done it. Writing a test, seeing it fail and then writing code to make that test succeed is a huge feeling of accomplishment. The great thing is if you’re doing TDD right then you’ll get that feeling of accomplishment frequently and continuously throughout the software lifecycle.

After more practice the red/green/red becomes a comfortable way to develop. You no longer wonder “How do I start this project?”; you know what to do…write a unit test. Eventually, if you’re passionate enough about programming, I firmly believe you’ll have a lot of fun writing unit tests and TDD.

you should write tests too

There’s a variety of different ways to create software. Do what’s best for you, makes you productive and results in maintainable, easy-to-read software. However, if you haven’t tried TDD I strongly suggest that you do. Give it a real shot too; not just write a single test and call it a day. Finish your next small project using TDD philosophies, you might just find that you like it.