build_test
3.5.23, released 5 weeks ago by tools.dart.dev
Utilities for unit testing Dart build_runner builders in memory
What it does
Provides helper functions to run builders in RAM, resolve source code, and read generated assets. It supports in-memory builds, real source files, and asset resolution via analyzer.
AI-written summary of version 3.5.23, based on the package's README and metadata. Report an inaccuracy
Use it when
- Testing custom build_runner builders
- Running small isolated build tests
- Need to resolve Dart source during tests
- Reading generated code as strings
Skip it when
- Production code that needs to run on device or web
- When you only need to generate code without testing
Strengths
- Runs builds entirely in memory, fast and isolated
- Supports real source files via TestReaderWriter
- Built-in helpers for resolving source code with analyzer
- Easy to read generated assets as strings
Weaknesses
- Only works with build_runner; not for general code generation
- Requires Dart 3.11+ and specific build_runner versions
- Limited to builder testing, not general utilities
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 15
Add dependency, import build_test, call testBuilder or testBuilders; no extra permissions needed
```dart
import 'package:build_test/build_test.dart';
void main() {
testBuilder(myBuilder, {
'test_package|lib/a.dart': '''
class TestClass {}
'''
});
}
```Alternatives
Packages that do the same job and could replace build_test.
- golden_test
A zero-dependency wrapper for Flutter golden tests with theme, locale, and multi-device support.
79Compare - patrol_log
Log package for Patrol, a Flutter-native UI testing framework
87Compare - very_good_test_runner
A Dart/Flutter test runner that streams TestEvent objects from dart test or flutter test.
88Compare - flame_test
Classes and helpers for testing applications built with the Flame Engine.
80Compare
Works with
Packages commonly used together with build_test: ones it builds on, ones built on it, and its own family.
- cryptobuild_test depends on itProvides SHA, MD5, and HMAC hashing functions for Dart.
- globbuild_test depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- package_configbuild_test depends on itRead and write Dart package configuration files.
- watcherbuild_test depends on itMonitors file system changes and notifies when files are added, removed, or modified.
- testbuild_test depends on itA full featured library for writing and running Dart tests across platforms.
- htmlbuild_test depends on itA Dart implementation of an HTML5 parser for strings and bytes.
- matcherbuild_test depends on itSupport for specifying test expectations via an extensible Matcher class.
- loggingbuild_test depends on itProvides configurable logging with levels and stream listeners for Dart apps.