test_benchmarker 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ CHANGELOG
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ lib
6
+ lib/test_benchmarker
7
+ lib/test_benchmarker.rb
8
+ lib/test_benchmarker/core_ext.rb
9
+ lib/test_benchmarker/test_benchmarks.rb
10
+ lib/test_benchmarker/test_suite.rb
11
+ test
12
+ test/test_core_ext.rb
13
+ test/test_helper.rb
14
+ test/test_test_benchmarker.rb
@@ -0,0 +1,176 @@
1
+ = test_benchmarker
2
+
3
+ test_benchmarker is a ruby library that benchmarks your Test::Unit test. It's intended to help you
4
+ pinpoint which tests take longer so you can improve the speed of your test suite.
5
+
6
+ == Download
7
+
8
+ Github: http://github.com/myronmarston/test_benchmarker/tree/master
9
+
10
+ Gem:
11
+ gem install myronmarston-test_benchmarker --source http://gems.github.com
12
+
13
+ == Usage
14
+
15
+ Require it in your ruby project:
16
+ require 'rubygems'
17
+ require 'test_benchmarker'
18
+
19
+ Or in Rails, with Rails 2.1+ gem support, add to your config/environments/test.rb:
20
+ config.gem 'myronmarston-test_benchmarker',
21
+ :lib => 'test_benchmarker',
22
+ :source => 'http://gems.github.com'
23
+
24
+ Your tests will only be benchmarked when you set the appropriate environment variable. Use BENCHMARK_TESTS
25
+ to have get the benchmark tests written to stdout.
26
+
27
+ When running tests from a single ruby file:
28
+ BENCHMARK_TESTS=true ruby path/to/test.rb
29
+
30
+ Or, when using rake:
31
+ rake test BENCHMARK_TESTS=true
32
+
33
+ Alternately, if you want the test benchmarks written to a file, you can use TEST_BENCHMARKS_FILE:
34
+ rake test TEST_BENCHMARKS_FILE=path/to/file
35
+
36
+ == Example Output
37
+
38
+ test_benchmarker prints two reports:
39
+
40
+ 1. Class Benchmark Results: Lists each of the Test::Unit::TestCase subclasses in the test run, from the slowest average test time to the fastest.
41
+ 2. Test Benchmark Results: Lists each of the tests that ran, from the slowest to the fastest.
42
+
43
+ Example output (taken from benchmarking {will_paginate's}[http://wiki.github.com/mislav/will_paginate] tests):
44
+
45
+ =========================== Class Benchmark Results ===========================
46
+ 1. 0.027 secs avg time, 1.193 secs total time, 45 tests for: FinderTest
47
+ 2. 0.005 secs avg time, 0.166 secs total time, 35 tests for: ViewTest
48
+ 3. 0.001 secs avg time, 0.001 secs total time, 1 tests for: ActiveRecordTestCase
49
+ 4. 0.000 secs avg time, 0.004 secs total time, 12 tests for: ArrayPaginationTest
50
+ 5. 0.000 secs avg time, 0.000 secs total time, 1 tests for: WillPaginate::ViewTestCase
51
+ ===============================================================================
52
+
53
+
54
+
55
+ ============================ Test Benchmark Results ============================
56
+ 1. 0.084 secs total time for: test_ability_to_use_with_custom_finders(FinderTest)
57
+ 2. 0.071 secs total time for: test_paginate_associations(FinderTest)
58
+ 3. 0.060 secs total time for: test_paginate_with_group(FinderTest)
59
+ 4. 0.059 secs total time for: test_paginate_in_named_scope_on_has_many_association(FinderTest)
60
+ 5. 0.058 secs total time for: test_container_id(ViewTest)
61
+ 6. 0.057 secs total time for: test_paginating_finder_doesnt_mangle_options(FinderTest)
62
+ 7. 0.057 secs total time for: test_should_use_scoped_finders_if_present(FinderTest)
63
+ 8. 0.057 secs total time for: test_paginate_with_order(FinderTest)
64
+ 9. 0.055 secs total time for: test_paginate_by_sql_respects_total_entries_setting(FinderTest)
65
+ 10. 0.055 secs total time for: test_implicit_all_with_dynamic_finders(FinderTest)
66
+ 11. 0.052 secs total time for: test_doesnt_remove_referenced_includes_in_count(FinderTest)
67
+ 12. 0.025 secs total time for: test_paginate_with_include_and_order(FinderTest)
68
+ 13. 0.024 secs total time for: test_hmt_with_include(FinderTest)
69
+ 14. 0.023 secs total time for: test_paginate_with_dynamic_finder(FinderTest)
70
+ 15. 0.022 secs total time for: test_paginate_with_per_page(FinderTest)
71
+ 16. 0.021 secs total time for: test_paginate_in_named_scope_on_habtm_association(FinderTest)
72
+ 17. 0.020 secs total time for: test_paginate_with_include_and_conditions(FinderTest)
73
+ 18. 0.019 secs total time for: test_named_scope_with_include(FinderTest)
74
+ 19. 0.018 secs total time for: test_paginate_in_named_scope_on_hmt_association(FinderTest)
75
+ 20. 0.018 secs total time for: test_paginate_with_joins(FinderTest)
76
+ 21. 0.018 secs total time for: test_paginated_each_with_named_scope(FinderTest)
77
+ 22. 0.018 secs total time for: test_parameter_api(FinderTest)
78
+ 23. 0.018 secs total time for: test_readonly(FinderTest)
79
+ 24. 0.018 secs total time for: test_adding_additional_parameters(ViewTest)
80
+ 25. 0.017 secs total time for: test_paginate_with_conditions(FinderTest)
81
+ 26. 0.017 secs total time for: test_paginate_array_of_ids(FinderTest)
82
+ 27. 0.017 secs total time for: test_paginated_each(FinderTest)
83
+ 28. 0.017 secs total time for: test_paginate_associations_with_include(FinderTest)
84
+ 29. 0.016 secs total time for: test_paginate_in_named_scope(FinderTest)
85
+ 30. 0.016 secs total time for: test_paginate_association_extension(FinderTest)
86
+ 31. 0.016 secs total time for: test_simple_paginate(FinderTest)
87
+ 32. 0.016 secs total time for: test_truth(FinderTest)
88
+ 33. 0.015 secs total time for: test_paginate_by_sql(FinderTest)
89
+ 34. 0.015 secs total time for: test_count_skips_select(FinderTest)
90
+ 35. 0.015 secs total time for: test_new_methods_presence(FinderTest)
91
+ 36. 0.015 secs total time for: test_paginate_by_sql_doesnt_change_original_query(FinderTest)
92
+ 37. 0.015 secs total time for: test_scoped_paginate(FinderTest)
93
+ 38. 0.015 secs total time for: test_count_with_scoped_select_when_distinct(FinderTest)
94
+ 39. 0.014 secs total time for: test_paginate_from(FinderTest)
95
+ 40. 0.014 secs total time for: test_guessing_the_total_count(FinderTest)
96
+ 41. 0.014 secs total time for: test_paginate_by_sql_strips_order_by_when_counting(FinderTest)
97
+ 42. 0.014 secs total time for: test_extra_parameters_stay_untouched(FinderTest)
98
+ 43. 0.014 secs total time for: test_removes_irrelevant_includes_in_count(FinderTest)
99
+ 44. 0.013 secs total time for: test_array_argument_doesnt_eliminate_count(FinderTest)
100
+ 45. 0.013 secs total time for: test_count_and_total_entries_options_are_mutually_exclusive(FinderTest)
101
+ 46. 0.013 secs total time for: test_count_select_when_distinct(FinderTest)
102
+ 47. 0.013 secs total time for: test_guessing_that_there_are_no_records(FinderTest)
103
+ 48. 0.008 secs total time for: test_removing_arbitrary_parameters(ViewTest)
104
+ 49. 0.005 secs total time for: test_full_output(ViewTest)
105
+ 50. 0.005 secs total time for: test_will_paginate_windows(ViewTest)
106
+ 51. 0.004 secs total time for: test_paginated_section(ViewTest)
107
+ 52. 0.004 secs total time for: test_will_paginate_using_renderer_instance(ViewTest)
108
+ 53. 0.004 secs total time for: test_will_paginate_eliminates_small_gaps(ViewTest)
109
+ 54. 0.004 secs total time for: test_custom_routing_with_first_page_hidden(ViewTest)
110
+ 55. 0.003 secs total time for: test_will_paginate(ViewTest)
111
+ 56. 0.003 secs total time for: test_will_paginate_with_options(ViewTest)
112
+ 57. 0.003 secs total time for: test_complex_custom_page_param(ViewTest)
113
+ 58. 0.003 secs total time for: test_custom_routing_page_param_with_dot_separator(ViewTest)
114
+ 59. 0.003 secs total time for: test_custom_routing_page_param(ViewTest)
115
+ 60. 0.003 secs total time for: test_prev_label_deprecated(ViewTest)
116
+ 61. 0.003 secs total time for: test_will_paginate_with_custom_page_param(ViewTest)
117
+ 62. 0.003 secs total time for: test_prev_next_links_have_classnames(ViewTest)
118
+ 63. 0.003 secs total time for: test_adding_additional_route_parameters(ViewTest)
119
+ 64. 0.003 secs total time for: test_will_paginate_preserves_parameters_on_get(ViewTest)
120
+ 65. 0.002 secs total time for: test_adding_anchor_parameter(ViewTest)
121
+ 66. 0.002 secs total time for: test_will_paginate_using_renderer_class(ViewTest)
122
+ 67. 0.002 secs total time for: test_page_entries_info_with_custom_entry_name(ViewTest)
123
+ 68. 0.002 secs total time for: test_will_paginate_doesnt_preserve_parameters_on_post(ViewTest)
124
+ 69. 0.002 secs total time for: test_will_paginate_without_page_links(ViewTest)
125
+ 70. 0.002 secs total time for: test_will_paginate_without_container(ViewTest)
126
+ 71. 0.002 secs total time for: test_escaping_of_urls(ViewTest)
127
+ 72. 0.002 secs total time for: test_deprecation_notices_with_page_count(ViewTest)
128
+ 73. 0.002 secs total time for: test_page_entries_info_with_single_page_collection(ViewTest)
129
+ 74. 0.002 secs total time for: test_page_entries_info(ViewTest)
130
+ 75. 0.002 secs total time for: test_page_entries_info_with_longer_class_name(ViewTest)
131
+ 76. 0.001 secs total time for: test_collection_name_can_be_guessed(ViewTest)
132
+ 77. 0.001 secs total time for: test_inferred_collection_name_raises_error_when_nil(ViewTest)
133
+ 78. 0.001 secs total time for: test_invalid_page(ArrayPaginationTest)
134
+ 79. 0.001 secs total time for: test_no_pagination_when_page_count_is_one(ViewTest)
135
+ 80. 0.001 secs total time for: test_paginated_collection(ArrayPaginationTest)
136
+ 81. 0.001 secs total time for: test_truth(ActiveRecordTestCase)
137
+ 82. 0.000 secs total time for: test_guessing_total_count(ArrayPaginationTest)
138
+ 83. 0.000 secs total time for: test_deprecated_api(ArrayPaginationTest)
139
+ 84. 0.000 secs total time for: test_rescue_response_hook_presence(ViewTest)
140
+ 85. 0.000 secs total time for: test_argument_error_with_params_and_another_argument(ArrayPaginationTest)
141
+ 86. 0.000 secs total time for: test_simple(ArrayPaginationTest)
142
+ 87. 0.000 secs total time for: test_invalid_per_page_setting(ArrayPaginationTest)
143
+ 88. 0.000 secs total time for: test_page_count_was_removed(ArrayPaginationTest)
144
+ 89. 0.000 secs total time for: test_no_complain(ViewTest)
145
+ 90. 0.000 secs total time for: test_no_complain(WillPaginate::ViewTestCase)
146
+ 91. 0.000 secs total time for: test_previous_next_pages(ArrayPaginationTest)
147
+ 92. 0.000 secs total time for: test_out_of_bounds(ArrayPaginationTest)
148
+ 93. 0.000 secs total time for: test_defaults(ArrayPaginationTest)
149
+ 94. 0.000 secs total time for: test_total_entries_has_precedence(ArrayPaginationTest)
150
+ ================================================================================
151
+
152
+
153
+ == LICENSE:
154
+
155
+ (The MIT License)
156
+
157
+ Copyright (c) 2009 Myron Marston, Kashless.org
158
+
159
+ Permission is hereby granted, free of charge, to any person obtaining
160
+ a copy of this software and associated documentation files (the
161
+ 'Software'), to deal in the Software without restriction, including
162
+ without limitation the rights to use, copy, modify, merge, publish,
163
+ distribute, sublicense, and/or sell copies of the Software, and to
164
+ permit persons to whom the Software is furnished to do so, subject to
165
+ the following conditions:
166
+
167
+ The above copyright notice and this permission notice shall be
168
+ included in all copies or substantial portions of the Software.
169
+
170
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
171
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
172
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
173
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
174
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
175
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
176
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 2
3
+ :patch: 1
4
+ :major: 1
@@ -0,0 +1,7 @@
1
+ module TestBenchmarker
2
+ VERSION = '0.9.2'
3
+ end
4
+
5
+ require 'test_benchmarker/test_benchmarks'
6
+ require 'test_benchmarker/test_suite'
7
+ require 'test_benchmarker/core_ext'
@@ -0,0 +1,56 @@
1
+ unless String.method_defined?(:constantize)
2
+ class String
3
+ # ported from ActiveSupport, so that we don't have to require all of active support for this gem.
4
+ # http://github.com/rails/rails/blob/dd2eb1ea7c34eb6496feaf7e42100f37a8dae76b/activesupport/lib/active_support/inflector.rb#L335-376
5
+ # Ruby 1.9 introduces an inherit argument for Module#const_get and
6
+ # #const_defined? and changes their default behavior.
7
+ if Module.method(:const_get).arity == 1
8
+ # Tries to find a constant with the name specified in the argument string:
9
+ #
10
+ # "Module".constantize # => Module
11
+ # "Test::Unit".constantize # => Test::Unit
12
+ #
13
+ # The name is assumed to be the one of a top-level constant, no matter whether
14
+ # it starts with "::" or not. No lexical context is taken into account:
15
+ #
16
+ # C = 'outside'
17
+ # module M
18
+ # C = 'inside'
19
+ # C # => 'inside'
20
+ # "C".constantize # => 'outside', same as ::C
21
+ # end
22
+ #
23
+ # NameError is raised when the name is not in CamelCase or the constant is
24
+ # unknown.
25
+ def constantize
26
+ names = self.split('::')
27
+ names.shift if names.empty? || names.first.empty?
28
+
29
+ constant = Object
30
+ names.each do |name|
31
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
32
+ end
33
+ constant
34
+ end
35
+ else
36
+ def constantize
37
+ names = self.split('::')
38
+ names.shift if names.empty? || names.first.empty?
39
+
40
+ constant = Object
41
+ names.each do |name|
42
+ constant = constant.const_get(name, false) || constant.const_missing(name)
43
+ end
44
+ constant
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ class Class
51
+ def is_subclass_of?(klass)
52
+ return false if self == Object && klass != Object
53
+ return true if self == klass
54
+ return self.superclass.is_subclass_of?(klass)
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ require 'ostruct'
2
+
3
+ module TestBenchmarker
4
+ class TestBenchmark
5
+ attr_reader :test_class, :test_name, :benchmark
6
+
7
+ def initialize(test_class, test_name, benchmark)
8
+ @test_class, @test_name, @benchmark = test_class, test_name, benchmark
9
+ TestBenchmarks.add(self)
10
+ end
11
+ end
12
+
13
+ class TestBenchmarks
14
+ def self.clear
15
+ @@classes = {}
16
+ @@tests = []
17
+ end
18
+
19
+ self.clear
20
+
21
+ def self.add(benchmark)
22
+ test_class = benchmark.test_class
23
+
24
+ # ignore some bogus test classes that get passed here when run in the context of a rails app...
25
+ return if test_class =~ /(rake_test_loader|::TestCase|::IntegrationTest)/
26
+
27
+ begin
28
+ test_class = test_class.constantize
29
+ rescue NameError
30
+ return
31
+ end
32
+ return unless test_class.is_subclass_of?(Test::Unit::TestCase)
33
+
34
+ @@classes[test_class] ||= OpenStruct.new
35
+ @@classes[test_class].benchmarks ||= []
36
+ @@classes[test_class].benchmarks << benchmark
37
+ @@tests << benchmark
38
+ end
39
+
40
+ def self.results
41
+ return if @@classes.nil? || @@classes.size == 0
42
+ results = StringIO.new
43
+ benchmark_attr = :real
44
+
45
+ class_benchmarks = []
46
+ @@classes.each do |test_class, obj|
47
+ obj.test_count = obj.benchmarks.size
48
+ obj.sum = obj.benchmarks.inject(0) {|sum, bmark| sum + bmark.benchmark.send(benchmark_attr)}
49
+ obj.avg = obj.sum / obj.test_count
50
+ obj.test_class = test_class
51
+ class_benchmarks << obj unless obj.benchmarks.nil? || obj.benchmarks.size == 0
52
+ end
53
+
54
+ results.puts "\n\n#{'=' * 27} Class Benchmark Results #{'=' * 27}"
55
+ class_benchmarks.sort {|a, b| b.avg <=> a.avg}.each_with_index do |cb, i|
56
+ results.puts "#{i + 1}.#{' ' * (4 - (i + 1).to_s.length)} #{format("%.3f", cb.avg)} secs avg time, #{format("%.3f", cb.sum)} secs total time, #{cb.test_count} tests for: #{cb.test_class.to_s}"
57
+ end
58
+ results.puts "#{'=' * 79}\n\n"
59
+
60
+ results.puts "\n\n#{'=' * 28} Test Benchmark Results #{'=' * 28}"
61
+ @@tests.sort {|a, b| b.benchmark.send(benchmark_attr) <=> a.benchmark.send(benchmark_attr)}.each_with_index do |t, i|
62
+ results.puts "#{i + 1}.#{' ' * (4 - (i + 1).to_s.length)} #{format("%.3f", t.benchmark.real)} secs total time for: #{t.test_name}"
63
+ end
64
+ results.puts "#{'=' * 80}\n\n"
65
+ results.string
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,29 @@
1
+ require 'benchmark'
2
+
3
+ if ENV['BENCHMARK_TESTS'] || ENV['TEST_BENCHMARKS_FILE']
4
+ class Test::Unit::TestSuite
5
+ @@run_count = 0
6
+
7
+ def run(result, &progress_block)
8
+ @@run_count += 1
9
+ begin
10
+ yield(STARTED, name)
11
+ @tests.each do |test|
12
+ TestBenchmarker::TestBenchmark.new(self.name, test.name, Benchmark.measure { test.run(result, &progress_block) })
13
+ end
14
+ yield(FINISHED, name)
15
+ ensure
16
+ @@run_count -= 1
17
+ # print the results as we're exiting the very last test run...
18
+ if @@run_count == 0
19
+ results = TestBenchmarker::TestBenchmarks.results
20
+ if ENV['TEST_BENCHMARKS_FILE']
21
+ File.open(ENV['TEST_BENCHMARKS_FILE'], 'a') { |f| f << results }
22
+ else
23
+ puts results
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class Foo; end
4
+ class FooSubclass < Foo; end
5
+ class FooSubSubclass < FooSubclass; end
6
+ class Bar; end
7
+
8
+ class TestCoreExt < Test::Unit::TestCase
9
+ def test_string_constantize
10
+ assert_equal TestCoreExt, 'TestCoreExt'.constantize
11
+ assert_equal FooSubSubclass, 'FooSubSubclass'.constantize
12
+ end
13
+
14
+ def test_string_constantize_for_bogus_class
15
+ assert_raise NameError do
16
+ 'This it not the name of a class!'.constantize
17
+ end
18
+ end
19
+
20
+ def test_class_is_subclass_of
21
+ assert FooSubclass.is_subclass_of?(Foo)
22
+ assert FooSubclass.is_subclass_of?(Object)
23
+
24
+ assert FooSubSubclass.is_subclass_of?(FooSubclass)
25
+ assert FooSubSubclass.is_subclass_of?(Foo)
26
+ assert FooSubSubclass.is_subclass_of?(Object)
27
+ end
28
+
29
+ def test_class_is_not_subclass_of
30
+ assert !Bar.is_subclass_of?(Foo)
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/test_benchmarker'
@@ -0,0 +1,117 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class Foo; end
4
+ class Class1 < Test::Unit::TestCase
5
+ def test_truth; end
6
+ end
7
+
8
+ class Class2 < Test::Unit::TestCase
9
+ def test_truth; end
10
+ end
11
+
12
+ class Class3 < Test::Unit::TestCase
13
+ def test_truth; end
14
+ end
15
+
16
+ class Class4; end
17
+
18
+ class TestTestBenchmarker < Test::Unit::TestCase
19
+ def setup
20
+ 1.upto(3) do |class_speed|
21
+ 1.upto(3) do |test_speed|
22
+ speed = class_speed * 0.01 + test_speed * 0.001
23
+ TestBenchmarker::TestBenchmark.new("Class#{class_speed}", "test_#{test_speed} (Class#{class_speed})", ::Benchmark.measure { sleep speed })
24
+ end
25
+ end
26
+
27
+ TestBenchmarker::TestBenchmark.new("Class4", "test_1 (Class4)", ::Benchmark.measure { sleep 0.01 })
28
+
29
+ @benchmarked_classes = TestBenchmarker::TestBenchmarks.send(:class_variable_get, '@@classes')
30
+ @benchmarked_tests = TestBenchmarker::TestBenchmarks.send(:class_variable_get, '@@tests').map{ |t| t.test_name }
31
+ @out = TestBenchmarker::TestBenchmarks.results
32
+ end
33
+
34
+ def teardown
35
+ TestBenchmarker::TestBenchmarks.clear
36
+ end
37
+
38
+ def test_has_expected_benchmarked_classes
39
+ assert_equal 3, @benchmarked_classes.keys.size
40
+
41
+ assert @benchmarked_classes.keys.include?(Class1)
42
+ assert @benchmarked_classes.keys.include?(Class2)
43
+ assert @benchmarked_classes.keys.include?(Class3)
44
+ end
45
+
46
+ def test_does_not_have_classes_not_descended_from_test_unit_testcase
47
+ assert !@benchmarked_classes.keys.include?(Class4)
48
+ end
49
+
50
+ def test_has_expected_benchmarked_tests
51
+ assert_equal 9, @benchmarked_tests.size
52
+
53
+ assert @benchmarked_tests.include?('test_1 (Class1)')
54
+ assert @benchmarked_tests.include?('test_2 (Class1)')
55
+ assert @benchmarked_tests.include?('test_3 (Class1)')
56
+ assert @benchmarked_tests.include?('test_1 (Class2)')
57
+ assert @benchmarked_tests.include?('test_2 (Class2)')
58
+ assert @benchmarked_tests.include?('test_3 (Class2)')
59
+ assert @benchmarked_tests.include?('test_1 (Class3)')
60
+ assert @benchmarked_tests.include?('test_2 (Class3)')
61
+ assert @benchmarked_tests.include?('test_3 (Class3)')
62
+ end
63
+
64
+ def test_does_not_have_tests_not_descended_from_test_unit_testcase
65
+ assert !@benchmarked_tests.include?("test_1 (Class4)")
66
+ end
67
+
68
+ def test_class_benchmark_results
69
+ # should be in order from slowest to fastest
70
+ assert_match class_benchmark_regex('Class3', 1), @out
71
+ assert_match class_benchmark_regex('Class2', 2), @out
72
+ assert_match class_benchmark_regex('Class1', 3), @out
73
+ end
74
+
75
+ def test_test_benchmark_results
76
+ # should be in order from slowest to fastest
77
+ assert_match test_benchmark_regex('test_3 (Class3)', 1), @out
78
+ assert_match test_benchmark_regex('test_2 (Class3)', 2), @out
79
+ assert_match test_benchmark_regex('test_1 (Class3)', 3), @out
80
+ assert_match test_benchmark_regex('test_3 (Class2)', 4), @out
81
+ assert_match test_benchmark_regex('test_2 (Class2)', 5), @out
82
+ assert_match test_benchmark_regex('test_1 (Class2)', 6), @out
83
+ assert_match test_benchmark_regex('test_3 (Class1)', 7), @out
84
+ assert_match test_benchmark_regex('test_2 (Class1)', 8), @out
85
+ assert_match test_benchmark_regex('test_1 (Class1)', 9), @out
86
+ end
87
+
88
+ private
89
+
90
+ # borrowed from zentest assertions...
91
+ def util_capture
92
+ require 'stringio'
93
+ orig_stdout = $stdout.dup
94
+ orig_stderr = $stderr.dup
95
+ captured_stdout = StringIO.new
96
+ captured_stderr = StringIO.new
97
+ $stdout = captured_stdout
98
+ $stderr = captured_stderr
99
+ yield
100
+ captured_stdout.rewind
101
+ captured_stderr.rewind
102
+ return captured_stdout.string, captured_stderr.string
103
+ ensure
104
+ $stdout = orig_stdout
105
+ $stderr = orig_stderr
106
+ end
107
+
108
+ def class_benchmark_regex(class_name, slowness_ranking)
109
+ # http://rubular.com/regexes/6815
110
+ /^#{slowness_ranking}\.\s+[\d\.]+ secs avg time, [\d\.]+ secs total time, [\d]+ tests for: #{Regexp.escape(class_name)}$/
111
+ end
112
+
113
+ def test_benchmark_regex(test_name, slowness_ranking)
114
+ # http://rubular.com/regexes/6816
115
+ /^#{slowness_ranking}.\s+[\d\.]+ secs total time for: #{Regexp.escape(test_name)}$/
116
+ end
117
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_benchmarker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Myron Marston
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-01 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A tool for benchmarking ruby Test::Unit tests.
17
+ email: myron.marston@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - Manifest.txt
26
+ - README.rdoc
27
+ - VERSION.yml
28
+ - lib/test_benchmarker/core_ext.rb
29
+ - lib/test_benchmarker/test_benchmarks.rb
30
+ - lib/test_benchmarker/test_suite.rb
31
+ - lib/test_benchmarker.rb
32
+ - test/test_core_ext.rb
33
+ - test/test_helper.rb
34
+ - test/test_test_benchmarker.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/myronmarston/test_benchmarker/
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --inline-source
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: A tool for benchmarking ruby Test::Unit tests.
64
+ test_files: []
65
+