A test method is a method whose name begins with `test` and contains executable assertions. In MiniTest, define it in a class that inherits from `Minitest::Test`; assertions determine whether the test passes. With `minitest/autorun`, test methods run automatically. section 15.5.1
Testing a card deck
After dealing one card, `test_deal_one` checks that the deck has 51 cards. After dealing five, `test_deal_many` checks for 47. A `setup` method creates a fresh deck before each test. section 15.5.1
Listing 15.6 card_test.rb: Testing the dealing accuracy of PlayingCards::Deck
require 'minitest/autorun' 1
require_relative 'cards'
class CardTest < Minitest::Test 2
def setup 3
@deck = PlayingCards::Deck.new
end
def test_deal_one 4
@deck.deal
assert_equal(51, @deck.size) 5
end
def test_deal_many 6
@deck.deal(5)
assert_equal(47, @deck.size)
end
end
See the complete MiniTest example, including the test class, setup method, and assertions. section 15.5.1
A small testing utility can emulate this pattern by using `inherited` and `method_added` callbacks to detect newly defined test methods, create an instance, run setup if present, and call the test. section 15.5.2




















































