import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:your_app/main.dart' as app;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('Counter increments and resets correctly', (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();
final Finder incrementButton = find.byKey(const Key('incrementButton'));
final Finder resetButton = find.byKey(const Key('resetButton'));
final Finder counterText = find.byKey(const Key('counterText'));
// Initial count should be 0
expect(find.text('Count: 0'), findsOneWidget);
// Tap increment twice
await tester.tap(incrementButton);
await tester.pumpAndSettle();
await tester.tap(incrementButton);
await tester.pumpAndSettle();
// Verify count is 2
expect(find.text('Count: 2'), findsOneWidget);
// Tap reset
await tester.tap(resetButton);
await tester.pumpAndSettle();
// Verify count is 0
expect(find.text('Count: 0'), findsOneWidget);
});
}This integration test uses Flutter's integration_test package to run the full app and simulate user taps.
We start the app, then find the increment and reset buttons by their keys.
We tap the increment button twice and check the counter text updates to 'Count: 2'.
Then we tap the reset button and verify the counter resets to 'Count: 0'.
This test confirms the app's UI and logic work together correctly.