Class: MiniTest::Unit::TestCase
- Inherits:
-
Object
- Object
- MiniTest::Unit::TestCase
- Includes:
- Assertions
- Defined in:
- lib/minitest/unit.rb
Overview
Subclass TestCase to create your own tests. Typically you'll want a TestCase subclass per implementation class.
Constant Summary
- PASSTHROUGH_EXCEPTIONS =
[NoMemoryError, SignalException, Interrupt, SystemExit]
- SUPPORTS_INFO_SIGNAL =
:nodoc:
Signal.list['INFO']
Instance Attribute Summary (collapse)
-
- (Object) __name__
readonly
:nodoc:.
Class Method Summary (collapse)
-
+ (Object) inherited(klass)
:nodoc:.
-
+ (Object) reset
:nodoc:.
-
+ (Object) test_methods
:nodoc:.
-
+ (Object) test_order
Defines test order and is subclassable.
-
+ (Object) test_suites
:nodoc:.
Instance Method Summary (collapse)
-
- (TestCase) initialize(name)
constructor
:nodoc:.
-
- (Boolean) passed?
Returns true if the test passed.
-
- (Object) run(runner)
Runs the tests reporting the status to runner.
-
- (Object) setup
Runs before every test.
-
- (Object) teardown
Runs after every test.
Methods included from Assertions
#_assertions, #_assertions=, #assert, #assert_block, #assert_empty, #assert_equal, #assert_in_delta, #assert_in_epsilon, #assert_includes, #assert_instance_of, #assert_kind_of, #assert_match, #assert_nil, #assert_operator, #assert_raises, #assert_respond_to, #assert_same, #assert_send, #assert_throws, #capture_io, #exception_details, #flunk, #message, #mu_pp, #pass, #refute, #refute_empty, #refute_equal, #refute_in_delta, #refute_in_epsilon, #refute_includes, #refute_instance_of, #refute_kind_of, #refute_match, #refute_nil, #refute_operator, #refute_respond_to, #refute_same, #skip
Constructor Details
- (TestCase) initialize(name)
:nodoc:
715 716 717 718 |
# File 'lib/minitest/unit.rb', line 715 def initialize name # :nodoc: @__name__ = name @passed = nil end |
Instance Attribute Details
- (Object) __name__ (readonly)
:nodoc:
674 675 676 |
# File 'lib/minitest/unit.rb', line 674 def __name__ @__name__ end |
Class Method Details
+ (Object) inherited(klass)
:nodoc:
726 727 728 |
# File 'lib/minitest/unit.rb', line 726 def self.inherited klass # :nodoc: @@test_suites[klass] = true end |
+ (Object) reset
:nodoc:
720 721 722 |
# File 'lib/minitest/unit.rb', line 720 def self.reset # :nodoc: @@test_suites = {} end |
+ (Object) test_methods
:nodoc:
743 744 745 746 747 748 749 750 751 752 753 754 755 |
# File 'lib/minitest/unit.rb', line 743 def self.test_methods # :nodoc: methods = public_instance_methods(true).grep(/^test/).map { |m| m.to_s } case self.test_order when :random then max = methods.size methods.sort.sort_by { rand(max) } when :alpha, :sorted then methods.sort else raise "Unknown test_order: #{self.test_order.inspect}" end end |
+ (Object) test_order
Defines test order and is subclassable. Defaults to :random but can be overridden to return :alpha if your tests are order dependent (read: weak).
735 736 737 |
# File 'lib/minitest/unit.rb', line 735 def self.test_order :random end |
+ (Object) test_suites
:nodoc:
739 740 741 |
# File 'lib/minitest/unit.rb', line 739 def self.test_suites # :nodoc: @@test_suites.keys.sort_by { |ts| ts.name } end |
Instance Method Details
- (Boolean) passed?
Returns true if the test passed.
760 761 762 |
# File 'lib/minitest/unit.rb', line 760 def passed? @passed end |
- (Object) run(runner)
Runs the tests reporting the status to runner
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/minitest/unit.rb', line 684 def run runner trap 'INFO' do warn '%s#%s %.2fs' % [self.class, self.__name__, (Time.now - runner.start_time)] runner.status $stderr end if SUPPORTS_INFO_SIGNAL result = '.' begin @passed = nil self.setup self.__send__ self.__name__ @passed = true rescue *PASSTHROUGH_EXCEPTIONS raise rescue Exception => e @passed = false result = runner.puke(self.class, self.__name__, e) ensure begin self.teardown rescue *PASSTHROUGH_EXCEPTIONS raise rescue Exception => e result = runner.puke(self.class, self.__name__, e) end trap 'INFO', 'DEFAULT' if SUPPORTS_INFO_SIGNAL end result end |
- (Object) setup
Runs before every test. Use this to refactor test initialization.
767 |
# File 'lib/minitest/unit.rb', line 767 def setup; end |
- (Object) teardown
Runs after every test. Use this to refactor test cleanup.
772 |
# File 'lib/minitest/unit.rb', line 772 def teardown; end |