Thursday, October 3, 2013

Addicted to Testing

I started learning to program using Ruby in April of 2012.  It is amazing how much I have learned in this year and a half.  I have built several novelty applications, an API for an iOS app, and a production application (Reading Glue).  Although I was able to build some decent applications, I have always questioned the reliability of my code.  If I tried hard enough, I seemed to always find holes.  Usually these types of errors were found by clicking around in the browser, and it took up a lot of my time.  There was an easy solution around this, and it was to learn testing.

People have told me about the importance of testing, but I have always had "more important things to learn."  I would tell myself that I did not have the time to learn, and really did not have the time to write extra code that was not essential.  Shipping a product quickly was more important in my eyes.  I recently started thinking about all of the time I spent clicking around in the browser to test out my code, and I realized that this time added up quickly.  I should have learned testing a year ago, and I needed to catch up quickly.

Starting yesterday, I have dedicated 5 hours each day to step away from what I am working on, and teach myself testing.  I have been using the book Everyday Rails Testing with RSpec along with Michael Hartl's Rails Tutorial, and I have a confession to make... I am addicted to testing.

So far I have learned some the basics of creating factories and writing RSpec tests for my models.  I look at my code much differently now.  As I write out different test specs, I start seeing holes in my current code.  Testing requires you to think about all the different ways you can make your code fail, and then find a solution to make the test pass.  In only 8 hours of practice, I have started changing the way I approach writing new methods.  Testing requires you to think about the problem and solution in a completely different way.  It makes you think about all the different ways something could "fail."

I still have so much to learn.  I have not even scratched the surface with what I need to know in order to create a solid test suite for Reading Glue.  If you have been putting off testing like me, then I really recommend you take a few days and work through some tutorials.  Don't just copy and paste code.  Type it out for muscle memory.  Better yet, don't even use their code.  Take the examples they use in the tutorials and apply it to one of your existing code bases.  That is what I have been doing.  Trust me, you will not regret it.