I have been getting into a lot of discussion lately regarding Test Driven Development. For those of you that do not know me, I am a TDD practioner (some may call me a fanatic). However, I was not always that way...
My TDD journey began a couple of years ago when someone handed me the book Extreme Programming Installed. I was part of team given the task to evaluate different Methodologies for Software Development. Fate led me to study Extreme Programming, but I will leave that for a different post. In my view, the best way to learn something is to put it into practice. Test Driven Development seemed like as good a candidate as any to start learning Extreme Programming, so I did.
Starting to practice Test Driven Development was not easy. For so long, I had operated in the mode of "Coding Blindly". The cycle of doing J2EE development was lengthy and insane: write code, compile, build distribution, deploy to application server, pray that it works!!! To change that mindset, as ridiculous as it was, was a challenge. Instead, I started to force myself to write tests against the business logic layer of my application. (Only recently have I started writing tests against the Data Access Layer, due to lack of methodologies of doing so). By writing my tests first, no longer was I operating blindly. Through the use of expectations, I had a goal in front of me that I was trying to reach and I was rewarded by the "almighty green bar" when I reached it.
I actually found myself working less. By writing the tests first, and building tests against objects and methods that were not even created yet, I allowed the IDE (Integrated Development Environment) to do all of the heavy lifting for me. With a click of a button, I was able to create classes and methods that allowed my tests to compile. With some creativity, I was able to control behavior of the dependencies, and test many scenarios that were impossible if not difficult to do while I was "Coding Blindly".
I have to admit, TDD was not easy to get used to. It required a lot of time, patience and research. I would like to challenge all of you who are reading this post to start applying some of the test driven practices. If you are having a hard time "chugging the TDD Koolaid" sip it instead. Take small steps and watch how more productive you become, how clean your code looks, how much more secure you will feel in the code that you write, and not to mention how much fun it will become.