簡體   English   中英

Minitest 5-套件級別的設置

[英]Minitest 5 - suite-level set up

如何使用minitest 5運行套件級別的設置和拆卸(在所有測試運行之前和之后)? 我正在嘗試復制為rails 3編寫的自定義測試運行器的功能,目前將其升級到rails 4。

這似乎是Ruby Minitest的副本:套件級或類級設置? 但是minitest 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

我一直在尋找類似的解決方案。 這是最小的自述文件中的建議解決方案:

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

不是最優雅的解決方案,但對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM