liveBook · Manning

File access interface

As explained in Test Driven: Practical TDD and Acceptance TDD for Java Developers

A file access interface is an application-defined abstraction that exposes file operations while hiding their underlying implementation.

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

How Test Driven: Practical TDD and Acceptance TDD for Java Developers covers it

How deep it goes
Defines the interface boundary and its testing benefit, but does not provide implementation steps or interface code.
Examples
Uses legacy code requiring test directories and a file-diff operation to motivate the advice.
What you can do after
Apply a custom interface to isolate file access and reduce test setup.
How it connects
Connects file access interfaces with Java's File API, streams, and testability.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Test Driven: Practical TDD and Acceptance TDD for Java Developers. The section links point to the parts of the book it draws on.