As developers we routinely work with code that is not our own, commonly in the form of third party APIs and application frameworks. This post discusses the scenario that almost every developer is likely to encounter at some stage in their career, namely what to do when you have to work with an API or framework dependency that makes unit testing seem impossible.
Faced with the prospect of developing code against a framework that doesn’t easily lend itself to unit testing you generally have a number of options.
The first and obvious choice for some is to abandon the idea of unit testing for part or all of the code that you have written. The reasoning here is, why the hell should I bother to test my code if the framework code lacks the same rigour. After all it’s not your fault, you can always blame the framework developers for painting you into this corner. This attitude is not exactly going to guarantee you a place amongst the great and good of Software Craftsmanship. The facts are that you, as a software professional, are responsible for verifying the code that you write. It is you who will ultimately have to support the code you write when it gets to production, giving you a great motivation to ensure that it functions correctly. Continue reading