The Need For Testing
In which I discover that yes Virginia, there is a good reason to write tests from the start.
I think I saw testing originally as a really nice thing to do in theory, but something that was quickly glossed over when you have your boss looking over your shoulder and wondering just why your project was late, just write the damn thing.
I actually discovered testing in Perl around 2003 with Test::Unit, when I was working at a company that did an online game site for school students. I read about testing, grabbed Test::Unit and Test::More and proceeded to do add some rudimentary tests to the model to do things like ensure that instantiating a new User model always created an object of the right type, that sort of thing.
I proudly told my boss this. His response was something like “neat”, with the unspoken subtext of “why aren’t you doing your work and wasting time doing this”.
Fast forward to the TDD happy fun world of rails.
I’m now a couple of weeks into my referee management site. It’s got a non-trivial, but not hugely complex set of models and interactions and I want to make some (moderately) major changes in some of the architecture. It terrifies me (well, maybe terrify is too strong a word) to make these changes without being able to just hit a button and know, know, that everything still works properly.
I started creating my models and controllers based on the Rails Tutorial site and using the “rspec_” syntax. IE:
script/generate rspec_controller Foo
This creates a set of default RSpec tests. Of course, the defaults are standard stuff, making sure that creating the object returns the right type of object, etc. Luckily a bit later on in the book there is a section on setting up your first tests.
The first challenge I have to create some of my tests (again harkening back to my “rails makes it seem sooo easy, but when you do it it’s a lot harder” rant), is that most of the pages on the site (that do interesting things anyway) are password protected. So now it’s a trek to find out how to deal with speccing out pages that are password protected to help fix the 24 failed tests I have sitting now when I run ‘spec spec’
So let that be a lesson to you all…. do your testing from the start, and set it up from the start like I should have (and knew I should have).