Component - Golden tests for UI
Golden tests check if a UI looks exactly as expected by comparing it to a saved image. They help catch visual bugs early by making sure the app's screen does not change unexpectedly.
Golden tests check if a UI looks exactly as expected by comparing it to a saved image. They help catch visual bugs early by making sure the app's screen does not change unexpectedly.
GoldenTestWidget ├─ Scaffold │ ├─ AppBar │ └─ Center │ └─ Text
expectLater with matchesGoldenFile is the standard way to compare UI to a golden image.testWidgets('Button golden test', (tester) async {
await tester.pumpWidget(MyButton());
await expectLater(find.byType(MyButton), matchesGoldenFile('button.png'));
});
What will happen if the current button UI differs visually from 'button.png'?testWidgets('Screen golden test', (tester) async {
await tester.pumpWidget(MyScreen());
expect(find.byType(MyScreen), matchesGoldenFile('screen.png'));
});expectLater with matchesGoldenFile to work asynchronously.Pass the test and this pattern moves unknown