Open13

Flutter / Integration Test

aoshima214aoshima214
pubspec.yaml
dev_dependencies:
  flutter_test:
    sdk: flutter
  integration_test:
    sdk: flutter
aoshima214aoshima214
lib/
  ...
integration_test/
  foo_test.dart
  bar_test.dart
test/
  # Other unit tests go here.
test_driver/
  integration_test.dart
aoshima214aoshima214
integration_test.dart
import 'package:integration_test/integration_test_driver.dart';

void main() => integrationDriver();
aoshima214aoshima214
app_test.dart
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

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

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  group('end-to-end test', () {
    testWidgets(
      'tap on the floating action button, verify counter',
      (tester) async {
        await app.main();
        // 描画が終わるのを待つ
        await tester.pumpAndSettle();

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

        // find.byTooltip = 指定されたツールチップウィジェットを検索.
        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);
      },
    );
  });
}

aoshima214aoshima214

対象ファイルのみテスト
flutter test integration_test/app_test.dart

ディレクトリ内の全てをテスト
flutter test integration_test

aoshima214aoshima214

Dart define を付けてテスト

flutter test integration_test --dart-define=FLAVOR=dev
flutter test integration_test/signup_test.dart --dart-define=FLAVOR=dev