Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save huynguyennovem/8bb63662321c0ec8235796994916bb70 to your computer and use it in GitHub Desktop.
Save huynguyennovem/8bb63662321c0ec8235796994916bb70 to your computer and use it in GitHub Desktop.
  1. Add test package to pubspec.yaml
  • Old:
flutter_driver:
  sdk: flutter
  • New:
integration_test:
  sdk: flutter

See (Migrating from flutter_driver)[https://docs.flutter.dev/testing/integration-tests/migration] for more information.

  1. Create test_driver and integration_test directory from project root dir

  2. Create test_driver/integration_test.dart file:

import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
  1. Create integration_test/app_test.dart file:
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'package:reproduce_issues_test/main.dart' as app;

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  group('end-to-end test', () {
    testWidgets('tap on the floating action button, verify counter',
            (tester) async {
          app.main();
          await tester.pumpAndSettle();

          // Verify the counter starts at 0.
          expect(find.text('0'), findsOneWidget);

          // Finds the floating action button to tap on.
          final Finder fab = find.byTooltip('Increment');

          // Emulate a tap on the floating action button.
          await tester.tap(fab);

          // Trigger a frame.
          await tester.pumpAndSettle();

          // Verify the counter increments by 1.
          expect(find.text('1'), findsOneWidget);
        });
  });
}
  1. Run integration test
  • Old flutter drive test:
flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart 
  • New flutter test:
flutter test integration_test/app_test.dart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment