Testably.Abstractions

July 13, 2026 ยท View on GitHub

Testably.Abstractions Testably.Abstractions.Testing Build Quality Gate Status Coverage

Injectable abstractions for the static parts of the .NET base class library (BCL) - file system, time and randomness - with feature-complete in-memory mocks for tests.

๐Ÿ“– Full documentation: docs.testably.org/Abstractions

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

PackagePurpose
Testably.AbstractionsProduction interfaces (IFileSystem, ITimeSystem, IRandomSystem)
Testably.Abstractions.TestingMockFileSystem, MockTimeSystem, MockRandomSystem
Testably.Abstractions.CompressionZip / ZipArchive extension methods on IFileSystem
Testably.Abstractions.AccessControlGetAccessControl / SetAccessControl on files and directories
Testably.Abstractions.MemoryMappedFilesMemoryMappedFile support on IFileSystem

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.