Your answer is correct, but perhaps too simplistic.
In the real world, as a rule, this is not so simple. Especially for legacy systems where a lot of code is connected too much, there are bad abstractions, inefficient language constructs, etc. It is especially difficult if there are no other tests and this happens.
Also, sometimes it’s just not easy to mock dependencies if they are hard-coded. Then it depends on the mocking capabilities of the framework, if it allows you to mock the final classes, static methods, etc.
It may be worth mentioning a few templates from the book "Working Effectively with Legacy Code."
source
share