Skip to main content

Testably.Abstractions

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

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.

CatalogService.cs
public class CatalogService(IFileSystem fileSystem)
{
public void Export(string json)
{
fileSystem.Directory.CreateDirectory("exports");
fileSystem.File.WriteAllText("exports/catalog.json", json);
}
}
CatalogServiceTests.cs
[Test]
public async Task Export_WritesCatalogToExportsFolder()
{
MockFileSystem fileSystem = new();
CatalogService sut = new(fileSystem);

sut.Export("""{ "title": "Red Square" }""");

await That(fileSystem.File.ReadAllText("exports/catalog.json"))
.IsEqualTo("""{ "title": "Red Square" }""");
}

Why Testably.Abstractions?​

Testably.Abstractions shares the IFileSystem interface with TestableIO.System.IO.Abstractions, so 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 behavior 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​