How to print start time in Ruby Test::Unit test run

I want to be able to print a timestamp of the test execution start time. Test::Unit doesn’t seem to be able to do this out-of-the-box, so here’s a monkeypatch I’ve written to put that functionality into-the-box!


class Test::Unit::AutoRunner
  alias original_run run
  def run
    puts "---===[ Starting at #{Time.now} ]===---\n\n"
    original_run
  end
end

When you run, you’ll see:

---===[ Starting at Thu Aug 13 23:13:24 +0100 2009 ]===---
Loaded suite /Users/nat/dev/add_start_time_to_test_unit
Started
...
Finished in 0.000731 seconds.
3 tests, 3 assertions, 0 failures, 0 errors

Very useful if you are highly iterative in the way you write tests… Are those results on screen from something I ran 2 minutes ago or 30 minutes ago? Well, now you have an easy way to find out!

This entry was posted in Automated Testing, Example Code, Making Life Easier, Ruby, Test::Unit, Tools and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>