3 ms·
I built my first and second rails projects without writing any tests. These were very small projects, just a few weeks of work on the larger one. By the time I
by jeremyjh 14y ago
I built my first and second rails projects without writing any tests. These were very small projects, just a few weeks of work on the larger one. By the time I was two weeks into the second project, I knew I was wasting a lot of time because I kept doing similar tests in the console when writing or modifying new code. But by that point I already felt like I had too much uncovered code to start writing tests. Cause if someone looked at it and saw just one test, what would they think ? (I know, right?)
The real reason is some kind of fear, that I do not exactly understand. Luckily, these were very small projects and never became anything I had to actually support or the tragedy would have been a lot more substantial - as it is my main loss was my own education.
My third rails project I forced myself to write specs and NEVER use the console for anything that slightly resembles testing - even if its just "trying things out". I put it all in tests and code and spent the effort to get my testing setup really fast and slick.
I've written dozens of tests now and still have a lot to learn but I'm definitely seeing a lot ofvalue. Hopefully it is not just cognitive dissonance. I've spent way more time on tests than on the actual code. I expect though that part will get better. I've been programming for sixteen years, but only testing for a few months.
One thing that really helped me is having some examples - the first I looked at were the tests that come with Devise, the other was the specs in Diaspora (http://github.com/diaspora/diaspora http://github.com/diaspora/diaspora) . They have like 1700 tests for that rails app. I'm doubt they are a paragon of testing virtue, but it is a hell of a lot more relevant than the same trivial examples I've been reading in blogs for the last decade.