Unit-tests are what saves a developers ass – and each app should have them, if it makes sense. So it depends
But for the project I’m working on right now it made sense, the perfect subject for unit testing. Or do you remember almost 100 different cases and conditions which might break if you change code? In my case I rewrote about 30% of the servlet code to be better structured and being capable of implementing a new requirement. Large parts where Spaghetti code without class inheritance or good usage of objects… subject to be thrown away or rewritten.
After trying the code for the first time after the rewrite the simple, LWP based unit tests immediately showed me where I had to “tweak” the code – and now that they again show a green PASSED I’m confident that it really works in production as well.
That’s how it should be – being confident that changes did not break any other part of the code.
Unit tests are way cool!
4 comments
citizen428 · 31.03.2009 at 12:56
That’s one thing I always like about the Ruby community, we have great tools for testing and doing BDD:http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.htmlhttp://www.thoughtbot.com/projects/shoulda/http://mocha.rubyforge.org/http://www.zenspider.com/ZSS/Products/ZenTest/http://rspec.info/http://cukes.info/http://eigenclass.org/hiki.rb?rcovAnd then of course you have Watir and friends for web application testing (this could be interesting for you):http://wtr.rubyforge.org/
m3 - Martin Leyrer · 07.04.2009 at 07:37
LWP based unit tests? Do you have a link/article on that? Would be interesting.
Michael Baierl · 07.04.2009 at 07:51
Hi Martin,not really, what I mean is a home-grown perl script that starts with the lineuse LWP::UserAgent;
Maybe I’ll post the script itself… the idea is to have handy functions to write tests liketest(“Non-existing page”, “/test/does_not_exist”, “404″);_pattern(“Must match”, “track_404.js”);which checks for a status code and further items on the page…
Scheme-less URLs in xDomain Dojo · mbaierl.com Blog · 22.03.2010 at 19:49
[...] it got fixed. I mean, how hard is it? Fix the simple bug, add a test case to the unit tests (you do unit test, don’t you?), run the tests [...]