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
-
#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
51 52 53 54 55 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 51 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.
62 63 64 65 66 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 62 def after_suite(suite) super @all_suite_times = @suite_times 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.
73 74 75 76 77 78 79 80 81 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 73 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.
87 88 89 |
# File 'lib/minitest/reporters/mean_time_reporter.rb', line 87 def reset_statistics! File.open(previous_runs_filename, 'w+') { |f| f.write('') } end |