Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 2
    If I have a legacy application with no unit-tests, and I want to include unit-tests for certain parts, do you think its better to first write out the integration tests for the legacy code. Once that is written, then you can uncouple the tight coupling, and create functions with interfaces that can be tested? Since you have the integration-test already written, you can then verify at each step of refactoring, that the new version of the code still works as desired? Commented Feb 24, 2018 at 23:57
  • 2
    @alpha_989, this is very much IMHO and I'm open to hearing other ideas, but I would prefer Integration Tests over Unit Tests for Legacy Code. In both cases, you would have to be certain that the methods are working correctly before adding any kind of testing, but Integration Testing ensures that the overall expectations of the methods are working as opposed to individual code elements. Commented Mar 29, 2018 at 19:33
  • @alpha_989 yes, that is an approach I have used several times on apps which were lacking test coverage. First I created integration tests which prevented regressions in the important functionalities of the app. Then it was possible to safely refactor the code to be more modular and unit testable without fear of breaking the app. Commented Mar 7, 2022 at 16:34