Make Test::Unit display errors earlier 5

Posted by pratik
on Saturday, March 14

Just a monkey patch to make Test::Unit display errors as soon as they happen.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require 'test/unit'
require 'test/unit/ui/console/testrunner'

class Test::Unit::UI::Console::TestRunner
  def add_fault(fault)
    hax_output(fault)
    @faults << fault
    output_single(fault.single_character_display, 1)
    @already_outputted = true
  end

  def hax_output(fault)
    @io.puts("\n")
    output_single(fault.short_display, 1) # fault.long_display for the full trace
    @io.puts("\n")
  end
end

Useful when your tests take too long to run.

Comments

Leave a response

  1. grosserMarch 14, 2009 @ 03:03 PM

    #test/test_helper.rb
    puts “using Test::Unit is a failure”

    okok… stupid comment :D

  2. PratikMarch 14, 2009 @ 03:28 PM

    I find RSpec DSL very retarded FWIW :-P

  3. Jason MorrisonMarch 14, 2009 @ 04:31 PM

    How interesting – I just patched my Test::Unit similarly, earlier this week. I elected to display full stack traces during the test run, and to suppress the test failure output at the end of the run.

    Unfortunately, I suppose this is only symptomatic of working on projects with long-running test suites, and that the best approach is to find places to improve the test suite performance. In the meantime, though, I wholeheartedly support this patching, and enjoy not having to wait to see my test failures!

  4. nicholas a. evansMarch 16, 2009 @ 01:35 PM

    For what it’s worth, if any rspec users (those who don’t find the DSL to be retarded) read this post and want something similar, I’ve written a progress bar output formatter for rspec that also displays errors (and their stacktraces) as soon as they occur: http://ekenosen.net/nick/devblog/2008/12/better-progress-bar-for-rspec/

    It’s quite nice for long running test suites, and I define “long running” as anything taking more than 5 seconds. :)

  5. Steven BristolDecember 22, 2009 @ 03:27 PM

    I just added this to our projects. Good stuff bro! Thanks!

Comment