Skip to content

Instantly share code, notes, and snippets.

@codeslinger
Created September 10, 2008 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeslinger/10103 to your computer and use it in GitHub Desktop.
Save codeslinger/10103 to your computer and use it in GitHub Desktop.
if ENV['BENCHMARK_TESTS'] && ENV['BENCHMARK_TESTS'] == 'on'
class Test::Unit::TestCase
# Replaces the regular Test::Unit::TestCase#run method with one that
# does benchmarking of each test method in a test case
def run result
yield(STARTED, name)
@_result = result
begin
setup
t = Time.now
__send__(@method_name)
elapsed = Time.now - t
STDOUT.printf("%.4f secs: %s#%s\n",
elapsed < 0.0 ? 0.0 : elapsed,
self.class,
@method_name)
rescue AssertionFailedError => e
add_failure(e.message, e.backtrace)
rescue Exception
raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
add_error($!)
ensure
begin
teardown
rescue AssertionFailedError => e
add_failure(e.message, e.backtrace)
rescue Exception
raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
add_error($!)
end
end
result.add_run
yield(FINISHED, name)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment