Test Driving TDD

I have become inspired and convinced by the idea of test driven development. Kent Beck said it best when he said –

We write code because that is our work and we write tests so that we know when we are done.

– Beck, K.  Extreme Programming Explained: Embrace Change

Or something like that.

So I have started kicking the tires on the metaphorical test driven development car. I started reading this book on Test Driven JavaScript Development (Developer’s Library). You can read the first few chapters for free on Safari books online. I think I’m going to get a subscription to Safari books for a while since it might be cheaper for me given my reading habits. I digress.

So I was sitting at my desk and I had to do some AJAX thingy with a form and an email address as the input for a client’s website. It looked pretty straight forward. But how do I give some email validation feedback to the user? I am thinking a regex expression would be nice. But I am not a regex ninja so I might need a few goes at this and how do I know if it works? The last thing I want is to prevent the user from entering valid email addresses – false positives are better than false negatives. Aha! How about I write some tests?

It took me a while and I had a lot of help from this guy’s blog but I came up with a regular expression that passed enough test cases for me to feel satisfied with it. Simply run it in your browser’s developer’s console to see it go.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s