I can run this command in the terminal to execute integration test on real device
flutter drive --target=test_driver/app.dart
But I don't know how to create Run/Debug configuration on Android Studio so I can debug the test. Please help me.
It doesn't require any special Run/Debug configuration on Android Studio to set breakpoints in an integration test using the integration_test package. This works the same for real devices, emulators, and Flutter Desktop.
$ flutter devices
3 connected devices:
XXXXXX (mobile) • XXXXXX • android-arm64 • Android XX.XX (API XX)
Linux (desktop) • linux • linux-x64 • Ubuntu 20.04.XX LTS XXX-generic
Chrome (web) • chrome • web-javascript • Google Chrome XXXXX
(See Run Test Flutter Apps Directly on Real Android Device in Windows MAC Tutorial | flutter-examples.com)
flutter create debug_at_device_2
cd debug_at_device_2
flutter pub get
Open the project in Android Studio.
Set a breakpoint in the _incrementCounter
method:
flutter_test
and integration_test
packages as dev dependency in the pubspec.yaml
:dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
flutter pub get
integration_test
and within that a file example_test.dart
with the following contents:import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:debug_at_device/main.dart' as app;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets("should increment counter", (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle();
expect(find.text('1'), findsOneWidget);
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle();
expect(find.text('2'), findsOneWidget);
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle();
expect(find.text('3'), findsOneWidget);
});
}
Make sure that the phone is unlocked (i.e. no screensaver)
Right-click on the run icon next to the main
method in example_test.dart
and then select the debug option from the context menu:
I have tested it using: