書いてみる
TODOアプリを想定してテストコードを書きます。
void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); group('group', () { testWidgets('start', (WidgetTester tester) async { app.main(); await tester.pumpAndSettle(); // 要素を確認する expect(find.byType(FloatingActionButton), findsWidgets); expect(find.text("メモ一覧"), findsOneWidget); // 新規作成ボタンをタップする await tester.tap(find.byType(FloatingActionButton)); await tester.pumpAndSettle(); // 内容を入力し、戻る await tester.enterText(find.byType(TextField), "new text"); await tester.pumpAndSettle(); await tester.tap(find.byType(IconButton)); await tester.pumpAndSettle(); // メモが反映されていることを確認する expect(find.text('new text'), findsOneWidget); }); }); }
ローカルで試す
デバイスを立ち上げた上で、下記を実行します。
flutter test integration_test
※容量が足りないと言われることが多いので、その際はエミュレータの wipe dataを実行します。
Test Labで実行する
基本的には上記のドキュメント通りに進められたものの、以下の二つで若干つまづきました。
- 依存関係を追加した後に、Gradle Syncはしなくて問題ない(癖でGradle Syncを押して、wrapper taskがないよと怒られました)
- ビルド時のコマンドの-Ptarget=の後は"file path"で囲む必要がある
./gradlew app:assembleDebug -Ptarget="integration_test/<name>_test.dart"