如何解决使用模块对Test :: Unit中的测试进行分组
| 当我在一个测试类中有许多测试时,我使用Module对测试进行分组。 由于我是Rails的新手,所以我的问题是: 这是对测试进行分组的正确方法,还是我在做非常愚蠢的事情而又不了解其他副作用? 这是代码: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
谢谢。
解决方法
问题是:通过将测试分组到模块中,您可以获得什么?
按照我卑鄙的传统,我只是将相似的测试进行分组,方法是将它们放置在彼此不远的地方,并给它们使用相同的名称前缀,例如:
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_/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。