How Test::Unit is clever to run test even thongh there is no main program? Thanks. 发自网易邮箱大师
MiniTest (which provides test/unit with Ruby 1.9 and newer) uses a couple different hooks:
1. Test suite requires ‘minitest/autorun’
2. 'minitest/autorun.rb’ loads the MiniTest library
3. MiniTest library sets an “inherited” hook: minitest/lib/minitest.rb at master · minitest/minitest · GitHub This hook on a parent class is called when it is subclassed by child class C.
4. ‘minitest/autorun.rb’ calls MiniTest.autorun
5. MiniTest.autorun sets an at_exit hook: minitest/lib/minitest.rb at master · minitest/minitest · GitHub This hook fires when the Ruby VM is exiting.
6. Test classes load, subclass Test::Unit or MiniTest equivalent. This puts them in the list of runnables.
7. Test classes have loaded, Ruby VM starts preparing to exit.
8. Ruby VM calls at_exit hook.
9. at_exit hook loops through the list of test classes, and runs them.
···
On Oct 5, 2014, at 09:46, Li <18831609423@163.com> wrote:
How Test::Unit is clever to run test even thongh there is no main program?