Issue
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.
Solution
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.
Steps to reproduce
- Make sure that your real device is connected:
$ 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)
- Create a new Flutter project with the classic counter app:
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:
- Add the
flutter_test
andintegration_test
packages as dev dependency in thepubspec.yaml
:
dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
- Update the packages again:
flutter pub get
- Create a new directory
integration_test
and within that a fileexample_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 your real device is selected as the default device in the runner bar:
Make sure that the phone is unlocked (i.e. no screensaver)
Right-click on the run icon next to the
main
method inexample_test.dart
and then select the debug option from the context menu:
- Step through the code once the breakpoint gets hit:
Environment
I have tested it using:
- Flutter version 2.5.1
- Android Studio version 2020.3.1
- Flutter plugin version 60.1.2
- Ubuntu 20.04
- Android phone
Answered By - Janux
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.