Class: Minitest::Reporters::MeanTimeReporter
- Inherits:
-
DefaultReporter
- Object
- StatisticsReporter
- BaseReporter
- DefaultReporter
- Minitest::Reporters::MeanTimeReporter
- Defined in:
- lib/minitest/reporters/mean_time_reporter.rb
Overview
This reporter creates a report providing the average (mean), minimum and maximum times for a test to run. Running this for all your tests will allow you to:
1) Identify the slowest running tests over time as potential candidates for improvements or refactoring. 2) Identify (and fix) regressions in test run speed caused by changes to your tests or algorithms in your code. 3) Provide an abundance of statistics to enjoy.
This is achieved by creating a (configurable) 'previous runs' statistics file which is parsed at the end of each run to provide a new (configurable) report. These statistics can be reset at any time by using a simple rake task:
rake reset_statistics
Defined Under Namespace
Classes: InvalidOrder, InvalidSortColumn
Constant Summary
Constants included from Minitest::RelativePosition
Minitest::RelativePosition::INFO_PADDING, Minitest::RelativePosition::MARK_SIZE, Minitest::RelativePosition::TEST_PADDING, Minitest::RelativePosition::TEST_SIZE
Instance Attribute Summary
Attributes inherited from BaseReporter
Class Method Summary collapse
-
.reset_statistics! ⇒ Boolean
Reset the statistics file for this reporter.
Instance Method Summary collapse
-
#after_suite(suite) ⇒ Hash<String => Float>
Copies the suite times from the DefaultReporter#after_suite method, making them available to this class.
- #initialize(options = {}) ⇒ Minitest::Reporters::MeanTimeReporter constructor
- #on_record(test)
- #on_report
- #on_start
-
#report
Runs the DefaultReporter#report method and then enhances it by storing the results to the 'previous_runs_filename' and outputs the parsed results to both the 'report_filename' and the terminal.
-
#reset_statistics!
Resets the 'previous runs' file, essentially removing all previous statistics gathered.
Methods inherited from DefaultReporter
#before_suite, #before_test, #print_failure, #record, #record_failure, #record_pass, #record_skip, #start
Methods included from ANSI::Code
Methods inherited from BaseReporter
#add_defaults, #after_test, #before_test, #record
Constructor Details
#initialize(options = {}) ⇒ Minitest::Reporters::MeanTimeReporter
55 56 57 58 59 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 55 def initialize( = {}) super @all_suite_times = [] end |
Class Method Details
.reset_statistics! ⇒ Boolean
Reset the statistics file for this reporter. Called via a rake task:
rake reset_statistics
34 35 36 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 34 def self.reset_statistics! new.reset_statistics! end |
Instance Method Details
#after_suite(suite) ⇒ Hash<String => Float>
Copies the suite times from the DefaultReporter#after_suite method, making them available to this class.
66 67 68 69 70 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 66 def after_suite(suite) super @all_suite_times = @suite_times end |
#on_record(test)
91 92 93 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 91 def on_record(test) super if [:show_progress] end |
#on_report
95 96 97 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 95 def on_report super if [:show_progress] end |
#on_start
87 88 89 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 87 def on_start super if [:show_progress] end |
#report
Runs the DefaultReporter#report method and then enhances it by storing the results to the 'previous_runs_filename' and outputs the parsed results to both the 'report_filename' and the terminal.
77 78 79 80 81 82 83 84 85 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 77 def report super create_or_update_previous_runs! create_new_report! write_to_screen! end |
#reset_statistics!
This method returns an undefined value.
Resets the 'previous runs' file, essentially removing all previous statistics gathered.
103 104 105 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 103 def reset_statistics! File.open(previous_runs_filename, 'w+') { |f| f.write('') } end |