Unit testing (and integration testing) is something every developer knows they should do, but quite often it can fall by the wayside – and I’m very guilty of that. When you start your a fresh project, it’s simple to design your application in a manner that will make unit testing easy, but what about when you want to test existing code Obviously, the answer completely depends on the code itself. However, from experience a lot of code out there is rigid and tightly coupled to other parts of the application, and I’ve found it nigh-on impossible to write any automated test for it.
Read more: https://chrisstclair.co.uk/unit-testing-making-existing-code-testable/