如何使用minitest 5运行套件级别的设置和拆卸(在运行所有测试之前和之后)?我正在尝试复制为Rails3编写的自定义测试运行器的功能,目前正在将其升级到Rails4。
这看起来可能是Ruby Minitest: Suite- or Class- level setup?的副本,但在最小的5.0+中,.runner的功能已被弃用
例如,我希望在所有测试之前和之后运行这些测试。
def before_suites
# code to run before the first test
p "Before everything"
end
def after_suites
# code to run after the last test
p "After everything"
end发布于 2018-01-29 19:05:46
我一直在寻找类似的解决方案。这是来自minitest README file的建议解决方案
describe Blah do
SETUP = begin
# ... this runs once when describe Blah starts
end
# ...
end我已经尝试过了,但是因为我使用了一些test_helper支持方法,所以对我来说效果不是很好。我写了这个简单的变通方法:
class SearchServiceTest < ActiveSupport::TestCase
@@init = 0
def setup
if @@init.eql?(0)
.. setup code goes here ..
@@init = 1
end
end
...
end不是最优雅的解决方案,但对我很有效。
https://stackoverflow.com/questions/32726759
复制相似问题