class Minitest::Test
公共类方法
i_suck_and_my_tests_are_order_dependent!() 点击切换源代码
当你的测试绝对需要按顺序执行时,请在测试的顶部调用此方法。这样做,就承认了你的测试很糟糕且很脆弱。
# File minitest-5.25.4/lib/minitest/test.rb, line 35 def self.i_suck_and_my_tests_are_order_dependent! class << self undef_method :test_order if method_defined? :test_order define_method :test_order do :alpha end end end
make_my_diffs_pretty!() 点击切换源代码
使此 Test
的差异比较使用 pretty_inspect,以便 assert_equal 中的差异可以有更多细节。注意:这比常规的 inspect 慢得多,但对于复杂对象更实用。
# File minitest-5.25.4/lib/minitest/test.rb, line 48 def self.make_my_diffs_pretty! require "pp" define_method :mu_pp, &:pretty_inspect end
parallelize_me!() 点击切换源代码
当您想并行运行测试时,请在测试顶部(在 Minitest::Test
子类或 describe
代码块内)调用此方法。这样做,就承认了你的测试非常棒。
# File minitest-5.25.4/lib/minitest/test.rb, line 60 def self.parallelize_me! include Minitest::Parallel::Test extend Minitest::Parallel::Test::ClassMethods end
runnable_methods() 点击切换源代码
返回所有以“test_”开头的实例方法。基于 test_order,这些方法要么排序、随机化(默认)或并行运行。
# File minitest-5.25.4/lib/minitest/test.rb, line 70 def self.runnable_methods methods = methods_matching(/^test_/) case self.test_order when :random, :parallel then srand Minitest.seed methods.sort.shuffle when :alpha, :sorted then methods.sort else raise "Unknown test_order: #{self.test_order.inspect}" end end
公共实例方法
run() 点击切换源代码
使用 setup/teardown 钩子运行单个测试。
# File minitest-5.25.4/lib/minitest/test.rb, line 87 def run time_it do capture_exceptions do SETUP_METHODS.each do |hook| self.send hook end self.send self.name end TEARDOWN_METHODS.each do |hook| capture_exceptions do self.send hook end end end Result.from self # per contract end