require "test/unit"
class BasicNumber
def initialize(number)
@number = number
end
def add(x)
@number + x
end
def multiply(x)
@number * x
end
end
class TC_MyTest < Test::Unit::TestCase #T必須大寫,否則通不過
def test_add
n=BasicNumber.new(10)
assert_equal(14,n.add(4),"This test about add is failure!")
#14 期望值,n.add(4) 實際值,"This test about add is failure!" 出錯時的提示。
end
def test_multiply
n=BasicNumber.new(10)
assert_equal(4,n.multiply(4),"This test about multiply is failure!")
end
end
Ruby學習筆記_單元測試
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.