4

Unit-tests are way cool!

Posted March 31st, 2009 in development and tagged , , by Michael

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 Responses so far.

  1. citizen428 says:

    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/

  2. m3 - Martin Leyrer says:

    LWP based unit tests? Do you have a link/article on that? Would be interesting.

  3. Michael Baierl says:

    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…

  4. [...] 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 [...]

Leave a Reply