Created
September 10, 2008 23:23
-
-
Save codeslinger/10103 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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