Golden File Testing
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.
Tag golden tests
Golden tests should be tagged to make it easier to run them separately from other tests.
testWidgets( 'render matches golden file', tags: TestTag.golden, (WidgetTester tester) async { await tester.pumpWidget(MyWidget());
await expectLater( find.byType(MyWidget), matchesGoldenFile('my_widget.png'), ); },);
testWidgets('render matches golden file', (WidgetTester tester) async { await tester.pumpWidget(MyWidget());
await expectLater( find.byType(MyWidget), matchesGoldenFile('my_widget.png'), );});
Configure your golden test tag
To configure a golden test tag across multiple files (or an entire package), create a dart_test.yaml
file and add the tag configuration:
tags: golden: description: "Tests that compare golden files."
You can then run the tests with the tag golden
in isolation, or quickly update
the golden files with the --update-goldens
flag:
flutter test --tags golden # Run only golden testsflutter test --tags golden --update-goldens # Update golden files