Skip to main content

Testably.Abstractions

Testably.Abstractions Testably.Abstractions.Testing

Testably.Abstractions is a feature-complete testing helper for the IFileSystem abstractions of the System.IO namespace, plus matching abstractions for time and randomness.

Inject. Mock. Test.​

Depend on IFileSystem, ITimeSystem and IRandomSystem in production. Swap in the in-memory mocks for tests — deterministic, cross-platform, no temp folders or Thread.Sleep.

ReportService.cs
public class ReportService(IFileSystem fileSystem)
{
public void Save(string content)
{
fileSystem.Directory.CreateDirectory("reports");
fileSystem.File.WriteAllText("reports/latest.xml", content);
}
}
ReportServiceTests.cs
[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 />");
}

Why another file system mock?​

Testably.Abstractions shares the IFileSystem interface with TestableIO.System.IO.Abstractions - your production code does not change when you switch testing libraries. What you get on top:

  • Advanced testing scenarios: FileSystemWatcher, SafeFileHandle, multiple drives with size limits.
  • Cross-platform simulation: run a Linux file system on Windows (and vice versa) to exercise platform-specific behaviour from a single CI job.
  • A second abstraction layer for time and randomness.

See Migration from TestableIO if you are already using TestableIO.

Where to go next​