In the final part of this series you will see how to refactor your tests. Keeping tests clean is important because it will make testing easier to do in the future.
# user_test.rb
def test_full_name
assert_equal 'John Doe', full_name('John', nil, 'Doe'), "nil middle initial"
assert_equal 'John H. Doe', full_name('John', 'H', 'Doe'), "H middle initial"
assert_equal 'John Doe', full_name('John', '', 'Doe'), "blank middle initial"
end
def full_name(first, middle, last)
User.new(:first_name => first, :middle_initial => middle, :last_name => last).full_name
end
本文介绍了一种保持测试案例整洁的方法,并通过具体的Ruby测试脚本示例展示了如何进行测试案例的重构,确保未来的测试工作更加容易执行。
883

被折叠的 条评论
为什么被折叠?



