goldenFileComparator top-level property
Compares rasterized image bytes against 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 byte-for-byte comparison of the
encoded 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 more intelligent comparator that knows how to decode the PNG images to raw pixels and compare pixel vales, reporting specific differences between the images.
See also:
- flutter_test for more information about how to configure tests at the directory-level.
Implementation
GoldenFileComparator get goldenFileComparator => _goldenFileComparator;
Implementation
set goldenFileComparator(GoldenFileComparator value) {
assert(value != null);
_goldenFileComparator = value;
}