LocalFileComparator class
The default GoldenFileComparator implementation for flutter test
.
The term golden file refers to a master image that is considered the true rendering of a given widget, state, application, or other visual representation you have chosen to capture. This comparator loads golden files from the local file system, treating the golden key as a relative path from the test file's directory.
This comparator performs a pixel-for-pixel comparison of the decoded PNGs, returning true only if there's an exact match. In cases where the captured test image does not match the golden file, this comparator will provide output to illustrate the difference, described in further detail below.
When using flutter test --update-goldens
, LocalFileComparator
updates the golden files on disk to match the rendering.
Local Output from Golden File Testing
The LocalFileComparator will output test feedback when a golden file test
fails. This output takes the form of differential images contained within a
failures
directory that will be generated in the same location specified
by the golden key. The differential images include the master and test
images that were compared, as well as an isolated diff of detected pixels,
and a masked diff that overlays these detected pixels over the master image.
The following images are examples of a test failure output:
File Name | Image Output |
---|---|
testName_masterImage.png | ![]() |
testName_testImage.png | ![]() |
testName_isolatedDiff.png | ![]() |
testName_maskedDiff.png | ![]() |
See also:
- GoldenFileComparator, the abstract class that LocalFileComparator implements.
- matchesGoldenFile, the function from flutter_test that invokes the comparator.
- Inheritance
- Object
- GoldenFileComparator
- LocalFileComparator
- Mixed in types
Constructors
- LocalFileComparator(Uri testFile, { Style pathStyle })
-
Creates a new LocalFileComparator for the specified
testFile
. [...]
Properties
Methods
-
compare(
Uint8List imageBytes, Uri golden) → Future< bool> -
Compares the pixels of decoded png
imageBytes
against the golden file identified bygolden
. [...]override -
update(
Uri golden, Uint8List imageBytes) → Future< void> -
Updates the golden file identified by
golden
withimageBytes
. [...]override -
generateFailureOutput(
ComparisonResult result, Uri golden, { Uri basedir, { String key: '' }) → void -
Writes out diffs from the ComparisonResult of a golden file test. [...]
inherited
-
getFailureFile(
String failure, Uri golden Uri basedir) → File -
Returns the appropriate file for a given diff from a ComparisonResult.
inherited
-
getTestUri(
Uri key, int version) → Uri -
Returns a new golden file Uri to incorporate any
version
number with thekey
. [...]inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
toString(
) → String -
Returns a string representation of this object.
inherited
Operators
-
operator ==(
dynamic other) → bool -
The equality operator. [...]
inherited