【发布时间】:2015-10-27 15:18:24
【问题描述】:
我正在努力更好地理解这三个原则。
我的问题是... 如何在不违反 SRP、OCP 和 DRY 的情况下编写测试?
由于测试文件中的代码相似,我当前的设计违反了 DRY。
我无法将测试文件合并在一起,因为这会违反打开/关闭原则。 (以后增加更多模块的可能性很大)
这里有什么我遗漏的吗? 如果有帮助,我正在为此使用 Ruby 和 Minitest。
模块文件
a.rb:
module A
# does an algorithm
end
b.rb:
module B
#does another algorithm
end
测试文件
a_test.rb:
class ModuleATest
# tests the algorithm
end
b_test.rb:
class ModuleBTest
# tests the algorithm
end
【问题讨论】:
-
我发现这个链接谈到了sharing examples。我需要进一步研究这个话题。
标签: testing dry solid-principles single-responsibility-principle open-closed-principle