goldenFileComparator top-level property

GoldenFileComparator goldenFileComparator

Compares pixels against those of a golden image file.

This comparator is used as the backend for matchesGoldenFile.

When using flutter test, a comparator implemented by LocalFileComparator is used if no other comparator is specified. It treats the golden key as a relative path from the test file's directory. It will then load the golden file's bytes from disk and perform a pixel-for-pixel comparison of the decoded PNGs, returning true only if there's an exact match.

When using flutter test --update-goldens, the LocalFileComparator updates the files on disk to match the rendering.

When using flutter run, the default comparator (TrivialComparator) is used. It prints a message to the console but otherwise does nothing. This allows tests to be developed visually on a real device.

Callers may choose to override the default comparator by setting this to a custom comparator during test set-up (or using directory-level test configuration). For example, some projects may wish to install a comparator with tolerance levels for allowable differences.

See also:

  • flutter_test for more information about how to configure tests at the directory-level.

Implementation

GoldenFileComparator get goldenFileComparator => _goldenFileComparator;
void goldenFileComparator= (GoldenFileComparator value)

Implementation

set goldenFileComparator(GoldenFileComparator value) {
  assert(value != null);
  _goldenFileComparator = value;
}