【问题标题】:Minitest 5 - suite-level set upMinitest 5 - 套件级设置
【发布时间】:2015-12-20 00:21:19
【问题描述】:

如何使用 minitest 5 运行套件级设置和拆卸(在所有测试运行之前和之后)?我正在尝试复制为 rails 3 编写的自定义测试运行器的功能,目前将其升级到 rails 4。

这可能看起来是 Ruby Minitest: Suite- or Class- level setup? 的副本,但 .runner 的功能在 minitest 5.0+ 中已被弃用

例如,我希望这些在所有测试之前和之后运行。

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

【问题讨论】:

    标签: ruby-on-rails ruby minitest


    【解决方案1】:

    我一直在寻找类似的解决方案。这是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
    

    不是最优雅的解决方案,但对我有用。

    【讨论】:

      猜你喜欢
      • 2011-10-09
      • 2015-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多