我需要在MiniTest的所有测试中的每个测试之前运行代码。
在我这样做之前:
MiniTest::Unit::TestCase.add_setup_hook do
...code to run before each test
end
我将MiniTest升级到版本4.7.2后,它显示以下错误:
undefined method `add_setup_hook' for MiniTest::Unit::TestCase:Class (NoMethodError)
我正在使用Ruby MRI 2.0.0p0。
SOLUTION
module MyMinitestPlugin
def before_setup
super
# ...code to run before all test cases
end
def after_teardown
# ... code to run after all test cases
super
end
end
class MiniTest::Unit::TestCase
include MyMinitestPlugin
end
add_setup_hook
在4.6.0中已删除。https://github.com/seattlerb/minitest/commit/792a480ebeb32983b9150adae575b7c396e2ae63
改为使用before_setup
。
我认为您正在寻找before_setup
方法。