Class: 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.
Direct Known Subclasses
Constant Summary collapse
- PASSTHROUGH_EXCEPTIONS =
[NoMemoryError, SignalException, Interrupt, SystemExit]
- SUPPORTS_INFO_SIGNAL =
:nodoc:
Instance Attribute Summary collapse
-
#__name__ ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.inherited(klass) ⇒ Object
:nodoc:.
-
.reset ⇒ Object
:nodoc:.
-
.test_methods ⇒ Object
:nodoc:.
-
.test_order ⇒ Object
Defines test order and is subclassable.
-
.test_suites ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(name) ⇒ TestCase
constructor
:nodoc:.
-
#passed? ⇒ Boolean
Returns true if the test passed.
-
#run(runner) ⇒ Object
Runs the tests reporting the status to
runner
. -
#setup ⇒ Object
Runs before every test.
-
#teardown ⇒ Object
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_output, #assert_raises, #assert_respond_to, #assert_same, #assert_send, #assert_silent, #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
#initialize(name) ⇒ TestCase
:nodoc:
734 735 736 737 |
# File 'lib/minitest/unit.rb', line 734 def initialize name # :nodoc: @__name__ = name @passed = nil end |
Instance Attribute Details
#__name__ ⇒ Object (readonly)
:nodoc:
693 694 695 |
# File 'lib/minitest/unit.rb', line 693 def __name__ @__name__ end |
Class Method Details
.inherited(klass) ⇒ Object
:nodoc:
745 746 747 |
# File 'lib/minitest/unit.rb', line 745 def self.inherited klass # :nodoc: @@test_suites[klass] = true end |
.reset ⇒ Object
:nodoc:
739 740 741 |
# File 'lib/minitest/unit.rb', line 739 def self.reset # :nodoc: @@test_suites = {} end |
.test_methods ⇒ Object
:nodoc:
762 763 764 765 766 767 768 769 770 771 772 773 774 |
# File 'lib/minitest/unit.rb', line 762 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 |
.test_order ⇒ Object
Defines test order and is subclassable. Defaults to :random but can be overridden to return :alpha if your tests are order dependent (read: weak).
754 755 756 |
# File 'lib/minitest/unit.rb', line 754 def self.test_order :random end |
.test_suites ⇒ Object
:nodoc:
758 759 760 |
# File 'lib/minitest/unit.rb', line 758 def self.test_suites # :nodoc: @@test_suites.keys.sort_by { |ts| ts.name } end |
Instance Method Details
#passed? ⇒ Boolean
Returns true if the test passed.
779 780 781 |
# File 'lib/minitest/unit.rb', line 779 def passed? @passed end |
#run(runner) ⇒ Object
Runs the tests reporting the status to runner
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 |
# File 'lib/minitest/unit.rb', line 703 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 |
#setup ⇒ Object
Runs before every test. Use this to refactor test initialization.
786 |
# File 'lib/minitest/unit.rb', line 786 def setup; end |
#teardown ⇒ Object
Runs after every test. Use this to refactor test cleanup.
791 |
# File 'lib/minitest/unit.rb', line 791 def teardown; end |