Support for the Ruby 2.1 series ended on March 31 2017. See here for details.

In Files

  • minitest/unit.rb

MiniTest::Unit::TestCase

Subclass TestCase to create your own tests. Typically you'll want a TestCase subclass per implementation class.

See MiniTest::Assertions

Public Class Methods

i_suck_and_my_tests_are_order_dependent!() click to toggle source

Call this at the top of your tests when you absolutely positively need to have ordered tests. In doing so, you're admitting that you suck and your tests are weak.

 
               # File minitest/unit.rb, line 1332
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!() click to toggle source

Make diffs for this TestCase use pretty_inspect so that diff in assert_equal can be more details. NOTE: this is much slower than the regular inspect but much more usable for complex objects.

 
               # File minitest/unit.rb, line 1345
def self.make_my_diffs_pretty!
  require 'pp'

  define_method :mu_pp do |o|
    o.pretty_inspect
  end
end
            
parallelize_me!() click to toggle source

Call this at the top of your tests when you want to run your tests in parallel. In doing so, you're admitting that you rule and your tests are awesome.

 
               # File minitest/unit.rb, line 1358
def self.parallelize_me!
  require "minitest/parallel_each"

  class << self
    undef_method :test_order if method_defined? :test_order
    define_method :test_order do :parallel end
  end
end
            

Public Instance Methods

io() click to toggle source

Return the output IO object

 
               # File minitest/unit.rb, line 1309
def io
  @__io__ = true
  MiniTest::Unit.output
end
            
io?() click to toggle source

Have we hooked up the IO yet?

 
               # File minitest/unit.rb, line 1317
def io?
  @__io__
end
            
passed?() click to toggle source

Returns true if the test passed.

 
               # File minitest/unit.rb, line 1400
def passed?
  @passed
end
            
run(runner) click to toggle source

Runs the tests reporting the status to runner

 
               # File minitest/unit.rb, line 1245
def run runner
  trap "INFO" do
    runner.report.each_with_index do |msg, i|
      warn "\n%3d) %s" % [i + 1, msg]
    end
    warn ''
    time = runner.start_time ? Time.now - runner.start_time : 0
    warn "Current Test: %s#%s %.2fs" % [self.class, self.__name__, time]
    runner.status $stderr
  end if runner.info_signal

  start_time = Time.now

  result = ""
  begin
    @passed = nil
    self.before_setup
    self.setup
    self.after_setup
    self.run_test self.__name__
    result = "." unless io?
    time = Time.now - start_time
    runner.record self.class, self.__name__, self._assertions, time, nil
    @passed = true
  rescue *PASSTHROUGH_EXCEPTIONS
    raise
  rescue Exception => e
    @passed = Skip === e
    time = Time.now - start_time
    runner.record self.class, self.__name__, self._assertions, time, e
    result = runner.puke self.class, self.__name__, e
  ensure
    %w{ before_teardown teardown after_teardown }.each do |hook|
      begin
        self.send hook
      rescue *PASSTHROUGH_EXCEPTIONS
        raise
      rescue Exception => e
        @passed = false
        runner.record self.class, self.__name__, self._assertions, time, e
        result = runner.puke self.class, self.__name__, e
      end
    end
    trap 'INFO', 'DEFAULT' if runner.info_signal
  end
  result
end
            
setup() click to toggle source

Runs before every test. Use this to set up before each test run.

 
               # File minitest/unit.rb, line 1408
def setup; end
            
teardown() click to toggle source

Runs after every test. Use this to clean up after each test run.

 
               # File minitest/unit.rb, line 1414
def teardown; end