2011-05-26 85 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_/ 
相关问题