Me too heh!
I started writing tests when I was changing some code that handled csv
data. I couldn't risk messing up the daily data import, but I had to
substantially change the way it worked. Aha I thought - better have
some good tests for this!
Amazingly, once I started looking at how to do the testing, the code
started to re-form itself into more discrete methods, and several of
them moved into the model (where unit testing is much easier). In my
case I had to spend a fair while developing the csv data for testing
import of data, but it was worth it. Now if I get any discrepancies,
I can start by running the tests and that helps me back into the
code. (My tests are still a bit tacky, but I am learning). One of
the things that kept putting me off was the seeming enormity of the
task of testing every possible condition for a particular method(s).
Others may have different views, but my guess is that it is best to
just get on and test the ones that immediately come to mind. Then the
others start to either gel or fall away as unnecessary.
I did find though, that as I tried to continue to work in tdd mode, my
end product delivery was seriously reduced. So at the moment, I am
not always building tests for everything. It would be nice if I
could, but the learning curve on writing tests is still holding me
back (and anyway, my experience is that rails is pretty rock solid -
and I tend to be a bit of a defensive programmer anyway). However, I
have changed one approach. Where in the past if I had a tricky bit of
code to write, I would bash away driving manual input and using
breakpoints, now I write a test for it and debug from there. Much
better because you get then get the test for free and repeatability of
edge cases is much more consistent.
I know I have to go back and redevelop a couple of areas of my app and
it is certainly my intention to build tests for these before I write
the code. I think the key is to just get the test framework up and
running and at least a few minimal tests working. It gives you a warm
feeling, and makes the step of adding more tests less daunting.
Much of what I have learned about Rails, and there is always something
new to pick up, has come from scanning the posts and particularly code
snippets on this group. Sadly though, there isn't a lot being posted
on tests and very little by way of examples. Maybe we could share
more on our test specifics - I suspect like us here, many rails
programmers need to get their foot on the first rung of the ladder.
I think what deters me, is that I am always pushing forward in my
understanding of how to do stuff, eg multiple models on a screen, auto
complete searching, redBox popups, factoring out views etc, etc. And
trying to write tests at the same time as figuring out how to do new
stuff is just too much for my brain. (I really like the railsCasts
perhaps there is scope for something similar for testing).
just my thoughts
Tonypm