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