Ruby的单元测试框架执行单元测试,即使没有人创建单元测试对象.例如,
在MyUnitTest.rb中
require 'test/unit' class MyUnitTest < Test::Unit::TestCase def test_true assert true end end
当我调用该脚本时
ruby MyUnitTest.rb
test_true方法自动执行.这是怎么做到的?
我试图提出一个可以做类似的框架.我不想在使用我的框架的每个模块的末尾“if __ FILE __ == $0”.
谢谢.
Test :: Unit使用 at_exit,它在应用程序退出之前立即运行代码:at_exit do puts "printed before quit" end .. other stuff
在关闭类或模块定义之后,我认为没有任何方法可以专门运行代码.
精彩评论