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.
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.
Works with
Packages commonly used together with test_descriptor: ones it builds on, ones built on it, and its own family.
- asynctest_descriptor depends on itUtility classes and helpers that extend Dart's async library.
- testtest_descriptor depends on itA full featured library for writing and running Dart tests across platforms.
- term_glyphtest_descriptor depends on itProvides useful Unicode glyphs and plain ASCII alternatives for command-line applications.
- source_spanSame familyStandard representation for source code locations, spans, and human-friendly error messages.
- test_apiSame familyThe user facing API for structuring Dart tests and checking expectations.
- test_processSame familyUtility for testing subprocesses with line‑by‑line stdout/stderr streams.
- test_reflective_loaderSame familyRuns test suites and methods discovered via reflection.
- codemodBuilt on test_descriptorWrite and run automated code modifications and refactors on a codebase.