????1. Test::Unit???

????Test::Unit???????????3????????????????????У?

????1) ????????????????????????

????2) ??????????????????????

????3) ?????????????????ò????

????Test::Unit?????ж?????????if???????????????????????????????????????????????????????????磺

require 'test/unit'
Class TestBug < Test::Unit::TestCase
def test_simple
assert_equal('ok'?? MyClass.new(1).to_s)
assert_equal('error'?? MyClass.new(2).to_s)
end
end

???????????????????????????磺

require 'test/unit'
Class TestBug < Test::Unit::TestCase
def test_raise
assert_raise(RuntimeError) {MyClass.new('null')}
assert_nothing_raised() {MyClass.new('normal')}
end
end

????2. ???????

??????????????????????????????????????????????????????????????????????????????????????????????????????????????в????

???????????????????Test::Unit::TestCase?????????ж???????????????test?????Test::Unit??÷?????????????е????????????test???????????????????

??????????????Щ?????????setup??teardown?????С??????TestCase???У????????setup????????????????????????У???????teardown???????????????????????????У????磺

require 'test/unit'
require 'dbi'
Class TestDB < Test::Unit::TestCase
def setup
@db = DBI.connetct('DBI:mysql:playlists')
end
def test_count
assert_equal('10'?? MyClass.new(1).get_count)
end
def teardown
@db.disconnect
end
end