module Minitest
The top-level namespace for Minitest
. Also the location of the main runtime. See Minitest.run
for more information.
Public Class Methods
Internal run method. Responsible for telling all Runnable sub-classes to run.
# File minitest-5.25.4/lib/minitest.rb, line 323 def self.__run reporter, options suites = Runnable.runnables.shuffle parallel, serial = suites.partition { |s| s.test_order == :parallel } # If we run the parallel tests before the serial tests, the parallel tests # could run in parallel with the serial tests. This would be bad because # the serial tests won't lock around Reporter#record. Run the serial tests # first, so that after they complete, the parallel tests will lock when # recording results. serial.map { |suite| suite.run reporter, options } + parallel.map { |suite| suite.run reporter, options } end
A simple hook allowing you to run a block of code after everything is done running. Eg:
Minitest.after_run { p $debugging_info }
# File minitest-5.25.4/lib/minitest.rb, line 97 def self.after_run &block @@after_run << block end
Registers Minitest
to run at process exit
# File minitest-5.25.4/lib/minitest.rb, line 70 def self.autorun Warning[:deprecated] = true if Object.const_defined?(:Warning) && Warning.respond_to?(:[]=) at_exit { next if $! and not ($!.kind_of? SystemExit and $!.success?) exit_code = nil pid = Process.pid at_exit { next if !Minitest.allow_fork && Process.pid != pid @@after_run.reverse_each(&:call) exit exit_code || false } exit_code = Minitest.run ARGV } unless @@installed_at_exit @@installed_at_exit = true end
Manually load plugins by name.
# File minitest-5.25.4/lib/minitest/manual_plugins.rb, line 9 def self.load *names names.each do |name| require "minitest/#{name}_plugin" self.extensions << name.to_s end end
Register a plugin to be used. Does NOT require / load it.
# File minitest-5.25.4/lib/minitest.rb, line 104 def self.register_plugin name_or_mod self.extensions << name_or_mod nil end
This is the top-level run method. Everything starts from here. It tells each Runnable sub-class to run, and each of those are responsible for doing whatever they do.
The overall structure of a run looks like this:
Minitest.autorun Minitest.run(args) Minitest.load_plugins Minitest.process_args Minitest.init_plugins Minitest.__run(reporter, options) Runnable.runnables.each runnable_klass.run(reporter, options) self.runnable_methods.each self.run_one_method(self, runnable_method, reporter) Minitest.run_one_method(klass, runnable_method) klass.new(runnable_method).run
# File minitest-5.25.4/lib/minitest.rb, line 269 def self.run args = [] self.load_plugins unless args.delete("--no-plugins") || ENV["MT_NO_PLUGINS"] options = process_args args Minitest.seed = options[:seed] srand Minitest.seed reporter = CompositeReporter.new reporter << SummaryReporter.new(options[:io], options) reporter << ProgressReporter.new(options[:io], options) unless options[:quiet] self.reporter = reporter # this makes it available to plugins self.init_plugins options self.reporter = nil # runnables shouldn't depend on the reporter, ever self.parallel_executor.start if parallel_executor.respond_to? :start reporter.start begin __run reporter, options rescue Interrupt warn "Interrupted. Exiting..." end self.parallel_executor.shutdown # might have been removed/replaced during init_plugins: summary = reporter.reporters.grep(SummaryReporter).first reporter.report return empty_run! options if summary && summary.count == 0 reporter.passed? end
Public Instance Methods
Filter object for backtraces.
# File minitest-5.25.4/lib/minitest.rb, line 44 cattr_accessor :backtrace_filter
Names of known extension plugins.
# File minitest-5.25.4/lib/minitest.rb, line 56 cattr_accessor :extensions
The signal to use for dumping information to STDERR. Defaults to “INFO”.
# File minitest-5.25.4/lib/minitest.rb, line 61 cattr_accessor :info_signal
Parallel
test executor
# File minitest-5.25.4/lib/minitest.rb, line 34 cattr_accessor :parallel_executor
Reporter object to be used for all runs.
NOTE: This accessor is only available during setup, not during runs.
# File minitest-5.25.4/lib/minitest.rb, line 51 cattr_accessor :reporter
The random seed used for this run. This is used to srand at the start of the run and between each Runnable.run
.
Set via Minitest.run
after processing args.
# File minitest-5.25.4/lib/minitest.rb, line 29 cattr_accessor :seed