I am interested in using Dependency Injection however I am confused as to how I am supposed to deal with external libs that were not designed with DI in mind.
For example, if I have some code that constructs objects that are within the scope of my project I can use an interface and then create mock versions as well as concrete versions of these.
However the same code might also use an external library to write to a database or call an API or whatever. The external library might only provide a concrete implementation of this.
This means that my code will have a mixture of concrete and abstract stuff in it and will force me into testing the external library at the same time as the rest of my code.
Should I be creating wrappers for all the external classes so that I can inject mock versions in? This seems like a lot of work.
If you do have to create mocks of concrete, third-party dependencies in order to isolate your own units, you can do so very easily using a mocking framework such as Mockito that makes use of instrumentation.
Unit testing should inform and reinforce your design decisions, not drive them, and you should be able to write them quickly to focus most of your efforts on the design and implementation of real code. Modern frameworks like Mockito make this possible.