Rails单元测试:如何将我自己的输出添加到单元测试结果中

时间:2010-01-06 13:29:41

标签: ruby-on-rails unit-testing

当运行Rails单元测试时,我会在测试失败时获得指定行号和方法的输出,例如:

  1) Failure:
test_05_photo_tag_add_remove(TC_javascript02Test)
    [./helper/helper.rb:6:in `handle_assert'
     ./helper/helper.rb:17:in `check_not_string'
     ./helper/helper.rb:134:in `check_for_ajax_remove_string'
     javascript.rb:39:in `test_05_photo_tag_add_remove']:
<false> is not true.

是否有可能将我自己的文字写入此堆栈?

提前致谢 彼得

1 个答案:

答案 0 :(得分:1)

大多数断言采用message参数,例如:

assert_equal 64, obj.size, "Size should be 64"

如果断言失败,除了通常的测试输出外,还会显示该消息。