Dart API ReferenceunittestMatcher

Matcher abstract class

expect Matchers must implement the Matcher class. The base Matcher class that implements this interface has a generic implementation of describeMismatch so this does not need to be provided unless a more clear description is required. The other two methods (matches and describe) must always be provided as they are highly matcher-specific.

abstract class Matcher {
  /**
   * This does the matching of the actual vs expected values.
   * [item] is the actual value. [matchState] can be supplied
   * and may be used to add details about the mismatch that are too
   * costly to determine in [describeMismatch].
   */
  abstract bool matches(item, MatchState matchState);

  /** This builds a textual description of the matcher. */
  abstract Description describe(Description description);

  /**
   * This builds a textual description of a specific mismatch. [item]
   * is the value that was tested by [matches]; [matchState] is
   * the [MatchState] that was passed to and supplemented by [matches]
   * with additional information about the mismact, and [mismatchDescription]
   * is the [Description] that is being built to decribe the mismatch.
   * A few matchers make use of the [verbose] flag to provide detailed
   * information that is not typically included but can be of help in
   * diagnosing failures, such as stack traces.
   */
  abstract Description describeMismatch(item, Description mismatchDescription,
      MatchState matchState, bool verbose);
}

Subclasses

BaseMatcher

Methods

abstract Description describe(Description description) #

This builds a textual description of the matcher.

abstract Description describeMismatch(item, Description mismatchDescription, MatchState matchState, bool verbose) #

This builds a textual description of a specific mismatch. item is the value that was tested by matches; matchState is the MatchState that was passed to and supplemented by matches with additional information about the mismact, and mismatchDescription is the Description that is being built to decribe the mismatch. A few matchers make use of the verbose flag to provide detailed information that is not typically included but can be of help in diagnosing failures, such as stack traces.

abstract bool matches(item, MatchState matchState) #

This does the matching of the actual vs expected values. item is the actual value. matchState can be supplied and may be used to add details about the mismatch that are too costly to determine in describeMismatch.