Skip to content
pubscout

matcher

0.12.20, released 7 months ago by dart.dev

Support for specifying test expectations via an extensible Matcher class.

WASM-ready
$ flutter pub add matcher
Source repository

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.

  • source_gen_test

    Test support for package:source_gen with helpers to validate success and failure cases.

  • flutter_svg_test

    A testing library for finding and verifying flutter_svg images in widget tests.

  • get_test

    A package that facilitates the creation of tests for applications built with GetX.

Works with

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