Testing and refactoring go hand in hand. Refactoring is all about improving code without changing its behavior. Testing is all about making sure you don't change the behavior while you are improving the code.
# models/user.rb
def full_name
[first_name, middle_initial_with_period, last_name].compact.join(' ')
end
def middle_initial_with_period
"#{middle_initial}." unless middle_initial.blank?
end
本文探讨了重构和测试在软件开发中的重要性。重构旨在改善代码质量而不改变其功能,而测试则确保在改进过程中不破坏原有行为。文章通过具体的代码示例展示了如何实现这些目标。
883

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



