When code accesses files directly in many places, tests may need real files and directory structures just to exercise a change. Put file access behind a custom interface, then have the rest of the code use that interface. This keeps file operations in one boundary and can reduce test setup, especially when working with legacy code. section 6.7.2
For operations concerned only with file contents, pass streams rather than file handles so tests can supply contents directly. Keep file objects only when the code also needs details such as location or size. section 6.7.2
