當你自己的測試套件執行完成後,會有一些結果。 我想保留在txt文件或HTML, thoes信息,但我不知道如何保存那些輸出的消息, 如果有人知道,請與我分享,在此先感謝 下面的代碼是我的實驗,但它不起作用。如何通過ruby將測試結果重定向到txt文件?
require File.join(File.dirname(__FILE__), 'person')
require "test/unit"
filename = "logfile.txt"
$logfile = File.new(filename,"a")
open(logfile,'a') { |f| f << $stdout}
class PersonTest < Test::Unit::TestCase
FIRST_NAME, LAST_NAME, AGE = 'Nathaniel', 'Taldtretbott', 25
def setup
@person = Person.new(FIRST_NAME, LAST_NAME, AGE)
end
def test_first_name
assert_equal "asv", @person.first_name,"try to compare"
end
def test_last_name
assert_equal "Taldtretbott", @person.last_name
end
def test_full_name
assert_equal FIRST_NAME + ' ' + LAST_NAME, @person.full_name
end
end
使用大括號圖標({})來修改您的代碼。 – 2011-03-30 15:10:53