2011-05-26 41 views
2

當我在一個測試類中有很多測試時,我使用Module對測試進行分組。在Test :: Unit中使用模塊對測試進行分組

因爲我很新的軌道,我的問題是:

是不是正確的方式來組測試或我在做很愚蠢的事情不知道其他的副作用?

下面是代碼:

require 'test_helper' 

module AttributeValidationTest 
    extend ActiveSupport::Testing::Declarative 

    test "should not ...." do 
    # ..... 
    end 

    # other tests here.... 
end 

module AnotherGroupTest 
    extend ActiveSupport::Testing::Declarative 

    # tests..... 
end 

# may be another modules.. 

class MyModelTest < ActiveSupport::TestCase 
    include AttributeValidationTest 
    include AnotherGroupTest 

end 

感謝。

回答

0

問題是:通過將模塊中的測試進行分組,您獲得了什麼?

我,在我卑微的傳統,通過將其放置不遠處對方,並給他們相同名稱前綴,就像剛組類似的測試:

def test_user_name_handles_strange_chars 
def test_user_name_handles_empty_string 
def test_user_name_... 

(你可以毫無問題使用新語法,test "name should handle strange...."

這可以幫助我進行測試的功能只有部分(我的完整的測試套件需要一個小時左右):

cd test && ruby unit/user_test.rb -n /test_user_name_/ 
相關問題