Useful design patterns for unit testing/TDD?

后端 未结 9 656
一个人的身影
一个人的身影 2021-01-29 17:54

Reading this question has helped me solidify some of the problems I\'ve always had with unit-testing, TDD, et al.

Since coming across the TDD approach to development I k

9条回答
  •  一向
    一向 (楼主)
    2021-01-29 18:39

    Michael Feather's book Working Effectively With Legacy Code is exactly what you're looking for. He defines legacy code as 'code without tests' and talks about how to get it under test.

    As with most things it's one step at a time. When you make a change or a fix try to increase the test coverage. As time goes by you'll have a more complete set of tests. It talks about techniques for reducing coupling and how to fit test pieces between application logic.

    As noted in other answers dependency injection is one good way to write testable (and loosely coupled in general) code.

提交回复
热议问题