- 追加された行はこの色です。
- 削除された行はこの色です。
&tag(Ruby1.9/UnitTest);
*目次 [#q03978c7]
#contents
*参考情報 [#kcdcf4c6]
-[[library test/unit:http://doc.ruby-lang.org/ja/1.9.2/library/test=2funit.html]]
*テストのファイル名 [#k1c338a9]
*テストライブラリ概論 [#p539d750]
-Ruby 1.8まではTest::Unitが標準添付でこれが標準。
-Ruby 1.9からminitestというライブラリにとってかわられ、Test::Unitもminitestで書き直された。
-特にこだわりがないならminitestを直接使えばよさそう。
*minitest [#t593c280]
**テストファイルの作成 [#qa29e917]
-test_foo.rbを作成。
#pre{{
require 'minitest/unit'
require 'foo'
MiniTest::Unit.autorun
class TestFoo < MiniTest::Unit::TestCase
def setup
@foo = Foo.new
end
# teardown はあまり使わない
def teardown
@foo = nil
end
def test_foo
assert_equal "foo", @foo.foo
end
def test_bar
assert_equal "bar", @foo.bar
end
end
}}
**テスト実行 [#yd571a16]
-直接スクリプトを実行する
$ ruby test_foo.rb
-bundleを使っている場合
$ bundle exec ruby test_foo.rb
*Test::Unit [#l4d69d2e]
**テストのファイル名 [#k1c338a9]
-test_foo.rbとする。
*テストの実装 [#j1810dcf]
**テストの実装 [#j1810dcf]
-テスト対象クラスをfooとするとき、次のように実装する。
#pre{{
require 'test/unit'
require 'foo'
class TC_Foo < Test::Unit::TestCase
def setup
@obj = Foo.new
end
# def teardown
# end
def test_foo
assert_equal("foo", @obj.foo)
end
def test_bar
assert_equal("bar", @obj.bar)
end
end
}}