我试图更好地理解这三个原则。
我的问题是……如何在不违反 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