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:
- Identify the slowest running tests over time as potential candidates for improvements or refactoring.
- Identify (and fix) regressions in test run speed caused by changes to your tests or algorithms in your code.
- 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) ⇒ Object
- #on_report ⇒ Object
- #on_start ⇒ Object
-
#report ⇒ Object
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! ⇒ void
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
54 55 56 57 58 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 54 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
33 34 35 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 33 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.
65 66 67 68 69 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 65 def after_suite(suite) super @all_suite_times = @suite_times end |
#on_record(test) ⇒ Object
90 91 92 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 90 def on_record(test) super if [:show_progress] end |
#on_report ⇒ Object
94 95 96 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 94 def on_report super if [:show_progress] end |
#on_start ⇒ Object
86 87 88 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 86 def on_start super if [:show_progress] end |
#report ⇒ Object
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.
76 77 78 79 80 81 82 83 84 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 76 def report super create_or_update_previous_runs! create_new_report! write_to_screen! end |
#reset_statistics! ⇒ void
This method returns an undefined value.
Resets the 'previous runs' file, essentially removing all previous statistics gathered.
102 103 104 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 102 def reset_statistics! File.delete(previous_runs_filename) if File.exist?(previous_runs_filename) end |