matcher
0.12.20, released 7 months ago by dart.dev
Support for specifying test expectations via an extensible Matcher class.
What it does
Provides a third-generation assertion mechanism for Dart unit and widget tests, drawing inspiration from Hamcrest. Includes a large number of built-in matchers for values, exceptions, futures, and streams, as well as support for creating custom matchers.
AI-written summary of version 0.12.20, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need expressive, composable assertions for unit or asynchronous tests.
- You want to validate complex data structures, exceptions, or stream events.
Skip it when
- You are not writing tests.
Strengths
- Extensible Matcher class allows defining custom validation logic.
- Rich set of built-in matchers for futures, streams, collections, and types.
- Detailed failure messages providing clear context on what went wrong.
Weaknesses
- Does not replace the underlying test runner framework (requires package:test or similar).
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 5
not documented
import 'package:test/test.dart';
void main() {
test('.split() splits the string on the delimiter', () {
expect('foo,bar,baz', allOf([
contains('foo'),
isNot(startsWith('bar')),
endsWith('baz')
]));
});
}Alternatives
Packages that do the same job and could replace matcher.
- bloc_test
A testing library that makes it easy to test blocs and cubits.
82Compare - source_gen_test
Test support for package:source_gen with helpers to validate success and failure cases.
78Compare - flutter_svg_test
A testing library for finding and verifying flutter_svg images in widget tests.
66Compare - get_test
A package that facilitates the creation of tests for applications built with GetX.
50Compare
Works with
Packages commonly used together with matcher: ones it builds on, ones built on it, and its own family.
- stack_tracematcher depends on itProvides parsing, inspection, and readable formatting of Dart stack traces.
- asyncmatcher depends on itUtility classes and helpers that extend Dart's async library.
- test_apimatcher depends on itThe user facing API for structuring Dart tests and checking expectations.
- term_glyphmatcher depends on itProvides useful Unicode glyphs and plain ASCII alternatives for command-line applications.
- built_valueSame familyImmutable value types with builders, enum classes and JSON serialization for Dart.
- platformSame familyCross‑platform abstraction for querying runtime platform info in Dart.
- httpSame familyA composable, Future‑based library for making HTTP requests across platforms.
- intlSame familyA Dart library for internationalization and localization, providing message translation, plural/gender handling, and date/number formatting.