Unit testing code with a file system dependency

Yay! Now it’s testable; I can feed in test doubles (mocks) to the DoIt method. But at what cost? I’ve now had to define 3 new interfaces just to make this testable. And what, exactly, am I testing? I’m testing that my DoIt function properly interacts with its dependencies. It doesn’t test that the zip file was unzipped properly, etc.

You have hit the nail right on its head. What you want to test is the logic of your method, not necessarily whether a true file can be addressed. You don´t need to test (in this unit test) whether a file is correctly unzipped, your method takes that for granted. The interfaces are valuable by itself because they provide abstractions that you can program against, rather than implicitly or explicitly relying on one concrete implementation.

Leave a Comment