A Developer WeBLOG RSS 2.0

One of the things that I've been trying to do lately to improve myself as a software developer is to apply TDD (Test Driven Development) to my day to day development work.

A little bit introductions on TDD, TDD is a Software Development methodology where test cases are written first to accommodate Software requirements/specs and then Codes are written afterwards to fulfill the tests. The whole idea is to let your tests dictate or drive your software development, i.e. "Your codes are born out of your tests". Codes that are written using TDD will be much simpler in general, because they are written just to pass your test cases. One of the problem that might arise when you write your code first is that you tend to get carried away and overcoding your solution. In some cases overcoding your solution can be a bad thing, because overcoding means you over-complicate things, things that are not necessarily have to be be implemented to fulfill your requirements.

The basic iterations of TDD is as follows:

  • Write your test case
  • Run your tests (the new one should fail)
  • Write your code
  • Run your tests (every test must passed)
  • Repeat

What Im hoping to achieve by implementing TDD is that, I want to overcome my habit of overthinking something (as I mentioned here). TDD should help me to set my mind to focus more on whats really important, which is to implement a solution that targets the required specification, nothing more and nothing less. Just as Rob Connery said in his MVC Storefront series, "TDD helps you to always challenge your assumption. Don't ever assume the code that you're writting is going to be needed unless if you test it first."

My first experience with TDD is a mix of good and bad. One of the first thing that I feel when doing TDD is that it feels weird to write my test case first. It's really hard to have the mentality to write the test case first, as I am very much used to just code away and worry about testing later. I have to admit that its not as easy as it sounds. Due to this I was not able to be as productive as I could be. Moreover, the fact that my company doesn't use any unit testing framework at all doesn't help for a bit. In fact I had trouble using VS2008 Unit Testing tool, it gives me compile error due to some project reference located in a network path. Couldn't be bother to fix it, I tried NUnit and it works like a charm.

Having said all that, after a few of TDD iterations Im starting to feel the benefit of TDD. Everything that TDD tries to achieve starting to make sense. From writing your test based on your requirements, to write your code to pass the test, and to produce another test (one test leads to another). Feels like it gives some rhythm to the way you write your solution. Unfortunately due to time constraint, I had to cheat my way to finish up my solution. I guess I still need some times to get used to it before I can really be productive again when using TDD. Anyway, I think the whole experience has been very positive and I will definitely keep on trying to apply TDD on my development work.

RWendi

Tuesday, October 21, 2008 12:21:46 PM UTC |  Comments [0]
Programming | TDD
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
All Content © 2010, RWendi