LoginSignup
28
28

test-unit3を触る。 6年ぶりのメジャーバージョンアップ

Last updated at Posted at 2014-08-03

注目はPower Assert

Power Assertはテスト途中の値を視覚的に表示してくれる。

library test/unit
http://docs.ruby-lang.org/ja/2.1.0/library/test=2funit.html
(このページのテストでtest-unit3の動作を見てみる。)

test-unit3を動かす。

動作確認環境

ubuntu14
ruby 2.1.2
gem 2.3.0

test-unitのインストール

gem install test-unit

使い方:

require "test-unit"

ファイル

foo.rb
test_foo.rb
(今回は特にtestディレクトリを作らず、同じ階層に置いた。)

foo.rb
class Foo
   def foo
     "foo"
   end
   def bar
     "foo"
   end
end
test_foo.rb
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

# 追加部分
  def test_foo
    assert do
      ("foo" == @obj.bar)
    end
  end

  def test_bar
    assert do
      ("bar" == @obj.bar)
    end
  end
end

実行方法

ruby test_foo.rb

実行結果

test_unit3.png

参考

Power Assertとは。

test-unit-power_assertをリリース - 継続にっき(2014-05-31)
http://www.callcc.net/diary/20140531.html#p01

test-unit 公式サイト

注、2014年8月4日午前現在
test-unitのドキュメント
リファレンスマニュアル
のリンクが死亡中。

28
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
28