We found this pattern by noticing that our tests generally focused on testing one method at a time. In the test methods we decided to clone the parameters that the method under test required.
For example, the method and test for addition could be:
class MathTest < Test::Unit::TestCaseA benefit to this style of test development is the ability to easily see which method is under test and what the values are of the arguments passed to the method under test. However, this does introduce a maintainability issue. Clearly, changing the parameters to the method under test will not automatically change the parameters to the test method. Additionally, when methods have multiple execution paths, thus requiring multiple test methods, the naming convention begins to break down.
def test_add(x=1, y=2)
assert_equal 3, Math.add(x,y)
end
end
class Math
def add(x, y)
x + y
end
end
When the effort is made to keep the definitions between the test and method under test synchronized this test definition convention has been shown to increase maintainability.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.