Tagging Your Test Cases 7

Posted by Bob Silva Mon, 18 Sep 2006 05:59:00 GMT

Here's a quick way to follow your tests a little more closely in your test.log. In your test setup, add the following line:
def setup
  RAILS_DEFAULT_LOGGER.debug "\n\e[0;31mRUNNING TEST CASE: #{name}\e[m\n"
end
When you run your tests, you will now see something similar to this.
Comments

Leave a response

  1. Lee O'Mara about 9 hours later:
    Not meaning to nitpick (and I would have sent this via email, but I couldn't locate your adderess), your IMG tags for this post aren't closed and that's causing problems downstream (eg. planet caboose's feed, at least in Vienna)
  2. Bob Silva about 19 hours later:
    Fixed, sorry about that.
  3. Carlos Gabaldon 1 day later:
    Very nice! Thanks for the tip!
  4. Mariano 6 days later:
    One of the things that when you see them you know that you missed it all along ;-) Isn't there a better place to put it? Somewhere were all Tests will benefit from it?
  5. Bob Silva 7 days later:
    I'm sure you can reopen some Test::Unit classes to make it happen. I didn't look into it at all.
  6. Simon Nicholls 8 days later:
    I think the setup method is a difficult extension point currently, & would require Module/Kernel hacks for method definition & method addition listening. Probably something like the code below would be enough, & is a decent enough fit since our logging does indeed aim to extend the test run rather than perform setup. Could be added directly to test_helper of course, but best wrapped as a Module
    alias_method :old_run, :run unless method_defined?(:old_run)
    def run(result, &progress_block)
      RAILS_DEFAULT_LOGGER.debug "\n\e[0;31mRUNNING TEST CASE: #{name}\e[m\n"
      old_run(result, &progress_block)
    end
    
    There are surely better ways than this though. Would be great to hear if anyone has done this kind of TestCase extension work
  7. Rob Sanheim 22 days later:
    Thanks for that solution, Simon. I add something similar to my setup calls, and once spent a good amount of time trying to get it into test::unit. After much frustration, I gave up - there were just too many places that setup was getting redefined and aliased.
Comments