This question already has an answer here:
I'm writing unit tests for a class that makes use of a general utilities module. In general I want to mock all the dependencies of the class, but mocking some of the utility functions feels weird. Some of them are simple functions for dealing with file paths, string manipulation, etc, and it seems like an implementation detail that the class under test uses this utility to implement its public API. If the code was refactored to not need that utility function, I wouldn't care and would prefer that the test not fail.
The problem is that some of the utilities functions depend on the filesystem, and obviously need to be mocked. So I'm considering either
- Leaving the utilities module as-is and mocking the filesystem module
- Or using most of the utilities module but mocking the individual functions that have dependencies on the filesystem
What have other people done in this scenario?