Skip to content
pubscout

test_descriptor

2.0.2, released 2 years ago by tools.dart.dev

Declarative API for creating and verifying file and directory structures in tests.

Quiet but busy
$ flutter pub add test_descriptor
Source repository

What it does

Provides an API using descriptors (such as `d.file` and `d.dir`) to declare filesystem structures. It automatically manages a temporary sandbox directory per test, allowing you to create files on disk and validate that file hierarchies match expected structures. It handles setup and cleanup of sandbox directories automatically when used with the `test` package.

AI-written summary of version 2.0.2, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Testing CLI tools, file parsers, or code generators that manipulate filesystem paths
  • Setting up and validating complex directory and file hierarchies in unit and integration tests
  • You need isolated sandbox environments per test run that are cleaned up automatically

Skip it when

  • Testing in environments without `dart:io` access such as web applications
  • Unit tests that do not involve filesystem interactions

Strengths

  • Declarative, tree-like structure makes complex folder setups easy to read and maintain
  • Automatic creation and teardown of the temporary test sandbox directory
  • Provides both creation (`create()`) and assertion (`validate()`) workflows

Weaknesses

  • Archive support (zip/tar) was removed in version 2.0.0
  • Relies directly on filesystem I/O rather than an in-memory mock filesystem

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
5
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;

void main() {
  test('file verification', () async {
    await d.dir('parent', [
      d.file('sibling.txt', 'hello world'),
      d.dir('child', [d.file('item.txt', 'item-content')])
    ]).create();

    await d.dir('parent', [
      d.file('sibling.txt', 'hello world')
    ]).validate();
  });
}

Alternatives

Packages that do the same job and could replace test_descriptor.

  • file

    Provides a full mockable filesystem interface (MemoryFileSystem) to test file operations in-memory without touching disk.

Works with

Packages commonly used together with test_descriptor: ones it builds on, ones built on it, and its own family.