尝试使用 Test::Unit 测试模块时遇到问题。我以前做的是这样的:
my_module.rb:
class MyModule
def my_func
5 # return some value
end
end
test_my_module.rb:
require 'test/unit'
require 'my_module'
class TestMyModule < Unit::Test::TestCase
include MyModule
def test_my_func
assert_equal(5, my_func) # test the output value given the input params
end
end
现在的问题是,如果 my_module 声明了一个初始化方法,它会被包含在测试类中,这会导致一系列问题,因为 Test::Unit 似乎覆盖/生成了一个初始化方法。所以我想知道测试模块的最佳方法是什么?
我还想知道我的模块此时是否应该成为一个类,因为初始化方法是用于初始化某些东西的状态。意见?
提前致谢 !