Test-driven development

By | 2011-12-22

As you all know, FlexWorld has been in development for more than 10 months. And I finally decided to give it a big overhaul. I recently read a book called “The Clean Coder” which is about good habits and techniques that every serious programmer should know of.

One thing that got my attention was “test-driven development”. In the past I didn’t really do serious software tests, i.e. regression and integration tests. Why? Because programmers are mostly lazy, and unit tests are somewhat boring to write.

But I realized I was completely wrong. When I began writing the first tests for FlexWorld (I removed everything before!) it actually felt quite good. The reason is the workflow: At first you write the tests for the interface you want to get (this implies thinking about it, which is very important). This also gives you practical use-cases. After that you implement the production code itself.

That happens step-by-step. For example for every single function you write a test, then the implementation. Thereafter you build and run the tests. If they pass and you’re somewhat sure your tests are complete and make sense, you KNOW your code is sane!

Before I’ve started with unit tests it always felt like: “Uh, this should work.. I will throw in some debug output messages and see if the result is something I expected.” But I was never sure if my code was sane completely. And when a bug happened, it felt normal to check the code, eventually run the debugger and see what was wrong.

I highly encourage everybody to TEST software and adapt the test-driven development workflow. It just feels better when you add a feature and know it doesn’t break anything.

Leave a Reply

Your email address will not be published. Required fields are marked *