模块 Minitest
Minitest
的顶层命名空间。 也是主运行时的位置。有关更多信息,请参阅 Minitest.run
。
公共类方法
__run(reporter, options) 点击切换源代码
内部运行方法。负责告诉所有可运行的子类运行。
# 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
after_run(&block) 点击切换源代码
一个简单的钩子,允许你在所有内容运行完毕后运行一段代码。例如
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
autorun() 点击切换源代码
注册 Minitest
在进程退出时运行
# 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
load(*names) 点击切换源代码
按名称手动加载插件。
# 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_plugin(name_or_mod) 点击切换源代码
注册要使用的插件。不要求/加载它。
# File minitest-5.25.4/lib/minitest.rb, line 104 def self.register_plugin name_or_mod self.extensions << name_or_mod nil end
run(args = []) 点击切换源代码
这是顶层运行方法。一切都从这里开始。它告诉每个可运行的子类运行,每个子类都负责执行它们所做的任何事情。
运行的整体结构如下所示
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
公共实例方法
backtrace_filter() 点击切换源代码
用于回溯的过滤器对象。
# File minitest-5.25.4/lib/minitest.rb, line 44 cattr_accessor :backtrace_filter
extensions() 点击切换源代码
已知扩展插件的名称。
# File minitest-5.25.4/lib/minitest.rb, line 56 cattr_accessor :extensions
info_signal() 点击切换源代码
用于向 STDERR 转储信息的信号。默认为 “INFO”。
# File minitest-5.25.4/lib/minitest.rb, line 61 cattr_accessor :info_signal
parallel_executor() 点击切换源代码
Parallel
测试执行器
# File minitest-5.25.4/lib/minitest.rb, line 34 cattr_accessor :parallel_executor
reporter() 点击切换源代码
用于所有运行的报告器对象。
注意:此访问器仅在设置期间可用,在运行期间不可用。
# File minitest-5.25.4/lib/minitest.rb, line 51 cattr_accessor :reporter
seed() 点击切换源代码
此运行使用的随机种子。 这用于在运行开始时和每次 Runnable.run
之间 srand。
在处理参数后通过 Minitest.run
设置。
# File minitest-5.25.4/lib/minitest.rb, line 29 cattr_accessor :seed