How does TDD make refactoring easier?

前端 未结 8 888
温柔的废话
温柔的废话 2021-02-01 16:53

I\'ve heard that projects developed using TDD are easier to refactor because the practice yields a comprehensive set of unit tests, which will (hopefully) fail if any change has

8条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 17:15

    changing an algorithm with a more efficient one, for example.

    This isn't refactoring, this is performance optimization. Refactoring is about improving the design of existing code. That is, changing its shape to better meet the needs the developer. Changing code with the intent of affecting externally visible behavior is not refactoring, and that includes changes for efficiency.

    Part of the value of TDD is that your tests help you hold the visible behavior constant while changing the way you produce that result.

提交回复
热议问题