Testably.Abstractions
May 2, 2026 ยท View on GitHub
Injectable abstractions for the static parts of the .NET BCL - file system, time and randomness - with feature-complete in-memory mocks for tests.
๐ Full documentation: docs.testably.org
Quick example
public class ReportService(IFileSystem fileSystem)
{
public void Save(string content)
{
fileSystem.Directory.CreateDirectory("reports");
fileSystem.File.WriteAllText("reports/latest.xml", content);
}
}
[Fact]
public async Task Save_WritesReportToReportsFolder()
{
var fileSystem = new MockFileSystem();
var sut = new ReportService(fileSystem);
sut.Save("<report />");
await Expect.That(fileSystem.File.ReadAllText("reports/latest.xml"))
.IsEqualTo("<report />");
}
Install
dotnet add package Testably.Abstractions
dotnet add package Testably.Abstractions.Testing
Then register the implementations in your DI container - see Getting Started.
Packages
| Package | Purpose |
|---|---|
Testably.Abstractions | Production interfaces (IFileSystem, ITimeSystem, IRandomSystem) |
Testably.Abstractions.Testing | MockFileSystem, MockTimeSystem, MockRandomSystem |
Testably.Abstractions.Compression | Zip / ZipArchive extension methods on IFileSystem |
Testably.Abstractions.AccessControl | GetAccessControl / SetAccessControl on files and directories |
Already on TestableIO?
Testably.Abstractions shares the IFileSystem interface with TestableIO.System.IO.Abstractions, so production code stays untouched. See the migration guide.
Contributing
Issues and pull requests are welcome - see CONTRIBUTING.md and the issue tracker.