testing - Writing tests without violating SRP, OCP, DRY -
i trying understand these 3 principles better.
my question is... how write tests without violating srp, ocp, , dry?
my current design violates dry because of similar code in test files.
i can't merge test files because violate open/closed principle. (there high probability of adding more modules later)
is there i'm missing here? if helps i'm using ruby , minitest this.
module files
a.rb:
module # algorithm end
b.rb:
module b #does algorithm end
test files
a_test.rb:
class moduleatest # tests algorithm end
b_test.rb:
class modulebtest # tests algorithm end
here how did it. ocp: classes test module not have modified srp: classes test module dry: creating including module tester can avoid duplication of code in tests.
module def algorithm(foo) #some implementation end end module b def algorithm(foo) #some implementation end end module module_tester def test_module_test assert_equal(@expected, @obj.algorithm(@to_test)) # test them end end class moduleatest < test_framework include module_tester def before @obj = object.new.extend(a) @expected = 'expected outcome goes here' @to_test = 'the thing test goes here' end end class modulebtest < test_framework include module_tester def before @obj = object.new.extend(b) @expected = 'the expected outcome' @to_test = 'the thing test' end end
Comments
Post a Comment