Web + Life Hack

〜True But Useless〜

【Rails】【Test】【比較】Test::UnitをHello worldしてみた。

弊社ではスキルアップ向上のため、
「就業時間中に1時間程度をスキルアップに充てる」ということを
今月から試験的に実施しています。
業務の都合上毎日というのは難しいのですが意識的に業務効率を行い、
出来るだけ多く実施するようにしています。
(効果があれば今後も継続していきたい。上司と相談予定。)


そんな大それたことはしていないのですが、
「Test::UnitとRspecだとどっちが良いんかなー。」
というのを検証してみました。


まずはTest::Unitから

1・test-unit取得

gem install test-unit

2・テストコード書く


g08m11_test.rb

require 'test/unit'
require 'cellphone-address-checker'
require 'digest/sha1'
class MyTest < Test::Unit::TestCase
# Called before every test method runs. Can be used
# to set up fixture information.
def setup
# Do nothing
#@g08m11 = g08m11.new
#@g08m11 = @g08m11.create
end
# Called after every test method runs. Can be used to tear
# down fixture information.
def teardown
# Do nothing
puts 'テスト終了です'
end
def empty?
true
end

# Fake test
def test_fail
# Do nothing
#assert_equal("テスト成功です!", @g08m11.present?)
assert 1 == 2, '1 は 2 と等しいはず'
# To change this template use File | Settings | File Templates.
fail('Not implemented')
end

3・テストコードを起動

ruby ./user_test.rb


次はRspecHello worldした内容について書いていきます。