当您自己的测试套件执行完毕后,会有一些结果。我想将这些信息保存在 txt 文件或 html 中,但我不知道如何保存那些输出的消息,如果有人知道,请与我分享,提前感谢以下代码是我的实验,但它不起作用.
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