import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:golden_toolkit/golden_toolkit.dart';
import 'package:your_app/counter_screen.dart';
void main() {
testGoldens('CounterScreen initial state', (tester) async {
await tester.pumpWidgetBuilder(const CounterScreen());
await screenMatchesGolden(tester, 'counter_screen_initial');
});
testGoldens('CounterScreen after increment', (tester) async {
await tester.pumpWidgetBuilder(const CounterScreen());
await tester.tap(find.text('Increment'));
await tester.pumpAndSettle();
await screenMatchesGolden(tester, 'counter_screen_after_increment');
});
}
This solution uses the golden_toolkit package to create golden tests for the CounterScreen.
First, it tests the initial UI with the counter at 0 and saves a golden snapshot named counter_screen_initial.
Second, it taps the 'Increment' button, waits for the UI to update, and saves another golden snapshot named counter_screen_after_increment.
These golden images help ensure the UI does not change unexpectedly in future code changes.