Wednesday, July 13, 2011

Another Chapter Down : TDD Rubular and Users!

So another chapter down, and another concept learned.  TDD or Test Driven Development, is something I have heard of in the past, but never have done myself, or fully understood its awesomeness.  This book is all TDD and its really helping me understand it.

Basically anytime you want to add a new feature or element to your site first, create a test for the feature.  As a simple example, say you are adding an "about us" link in your navigation, before writing any code, first write a test that checks for the links existence then that the correct page renders.  So starting with a failed test, basically write as minimal amount of code to make the test pass.

What's the point?
So far I have thought of a few amazing reasons for this.

First, automated testing from the get go.  This can check to make sure you don't break anything when updating any features. Instead of clicking through the site constantly and still missing little things, the tests check these automatically, so long as you wrote them correctly.  

If it sounds like its a lot of work to write these tests, it is.  Its typically more than the actual code itself, and should be, but they are simpler to write, and save tons of time in the process.

Another thing, since you are basically writing code to make the tests pass, it really lets you focus on the one thing at hand and keeps you less distracted, and you end up writing a lot less unnecessary code.  You can always go back later and clean that up making sure the tests still work.

I can't wait to start using this more.

Also I have made my first users:

Also as always you can see my progress so far here http://severe-robot-761.heroku.com/

Oh and one last thing!

In order to validate email we did some regex, and the book linked to a really cool ruby regex tester, so I thought i'd share http://www.rubular.com/

No comments:

Post a Comment