System.IO.Abstractions mirrors the System.IO API through injectable IFileSystem interfaces so production code can swap in mocks or in-memory file systems during tests.
Overview
TestableIO System.IO.Abstractions wraps common file and directory operations behind IFileSystem and related interfaces. Instead of calling static methods such as File.ReadAllText directly, applications use IFileSystem.File.ReadAllText with the same surface area, which keeps production behavior unchanged while tests substitute fakes.
A default FileSystem implementation delegates to real System.IO calls, and optional TestingHelpers provide MockFileSystem with MockFileData and MockDirectoryData for scenarios that do not need a full mock framework. Since version 4.0, top-level APIs expose interfaces rather than only abstract classes, so mock libraries can replace the entire file system.
Casting helpers can wrap Framework FileInfo and similar untestable types into testable wrapper types. The package ships on NuGet under both prefixed and unprefixed names; maintainers recommend the TestableIO-prefixed packages to distinguish them from official .NET libraries.
Testably.Abstractions is a related project that shares the same interfaces, so production code can stay the same when switching testing stacks. TestableIO remains maintained for stability; Testably targets advanced scenarios such as FileSystemWatcher simulation, extra abstractions like time and randomness, and cross-platform behavior validation.
Key features
- IFileSystem injection pattern
- MockFileSystem test helpers
- Interface-based mockable APIs
- Wrapper types for FileInfo-like APIs
- TestingHelpers NuGet package
- Compatible with Testably.Abstractions
Use cases
- Unit testing code that reads files
- In-memory file system in tests
- Dependency injection for I/O
- Mocking FileSystemWatcher scenarios via Testably