easy_mock_io

In-memory dart:io for Flutter tests. MockMemoryIO.init() replaces IOOverrides.global with a MemoryFileSystem, so every File / Directory your code under test touches runs in memory instead of hitting the real disk — no temp files to clean up, and tests stay isolated from each other.

Usage

import 'package:easy_mock_io/easy_mock_io.dart';

setUp(() => MockMemoryIO.init());
tearDown(() => IOOverrides.global = null);

test('writes go to memory, not disk', () {
  File('/notes/todo.txt')
    ..createSync(recursive: true)
    ..writeAsStringSync('hi');

  expect(File('/notes/todo.txt').readAsStringSync(), 'hi');
});
  • MockMemoryIO.init([MemoryFileSystem? fs, MemoryIOConfig config]) installs the override. Pass a pre-seeded filesystem to start with files already present; omit it for an empty one. config controls the asset seeding and root path.
  • File locks are no-ops. lock / unlock (sync and async) return immediately, so tests that open the same path in parallel can't deadlock on an exclusive lock the memory filesystem wouldn't honour anyway.
  • Assets are seeded from the folder named by the UNIT_TEST_ASSETS environment variable, and /app_root is created up front.

init sets IOOverrides.global; reset it with IOOverrides.global = null in tearDown (or install a fresh one per test) so overrides don't leak.

Libraries

easy_mock_io