I am trying to run a basic flutter integration test to invoke my main app widget but it's failing. I have followed the approach as described in the official docs [https://docs.flutter.dev/testing/integration-tests]
Here is the complete stack trace:
Running "flutter pub get" in my_app... 2,651ms
Running Gradle task 'assembleStagingDebug'...
Running Gradle task 'assembleStagingDebug'... Done 35.1s
✓ Built build/app/outputs/flutter-apk/app-staging-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk... 10.5s
VMServiceFlutterDriver: Connecting to Flutter application at http://127.0.0.1:56037/_2tNx8J1Lj8=/
VMServiceFlutterDriver: Isolate found with number: 4501853398952855
VMServiceFlutterDriver: Isolate is paused at start.
VMServiceFlutterDriver: Attempting to resume isolate
D/EGL_emulation(29263): eglMakeCurrent: 0xa27a1bc0: ver 3 0 (tinfo 0xa2a835b0)
I/flutter (29263): 00:00 +0: (setUpAll)
VMServiceFlutterDriver: Connected to Flutter application.
I/flutter (29263): 00:00 +1: My Tests Basic Home Screen Smoke test
I/flutter (29263): (The following exception is now available via WidgetTester.takeException:)
I/flutter (29263): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (29263): The following assertion was thrown running a test:
I/flutter (29263): 'package:flutter/src/foundation/binding.dart': Failed assertion: line 55 pos 12:
I/flutter (29263): '!_debugInitialized': is not true.
I/flutter (29263):
I/flutter (29263): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (29263): more information in this error message to help you determine and fix the underlying cause.
I/flutter (29263): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (29263): https://github.com/flutter/flutter/issues/new?template=2_bug.md
I/flutter (29263):
I/flutter (29263): When the exception was thrown, this was the stack:
I/flutter (29263): #2 new BindingBase (package:flutter/src/foundation/binding.dart:55:12)
I/flutter (29263): #3 new _WidgetsFlutterBinding&BindingBase&GestureBinding (package:flutter/src/widgets/binding.dart)
I/flutter (29263): #4 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding (package:flutter/src/widgets/binding.dart)
I/flutter (29263): #5 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding (package:flutter/src/widgets/binding.dart)
I/flutter (29263): #6 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding
(package:flutter/src/widgets/binding.dart)
I/flutter (29263): #7 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding
(package:flutter/src/widgets/binding.dart)
I/flutter (29263): #8 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding
(package:flutter/src/widgets/binding.dart)
I/flutter (29263): #9 new
_WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding
(package:flutter/src/widgets/binding.dart)
I/flutter (29263): #10 new WidgetsFlutterBinding (package:flutter/src/widgets/binding.dart)
I/flutter (29263): #11 new CustomImageCache (package:app/custom_image_cache.dart)
I/flutter (29263): #12 main (package:app/main_staging.dart:51:3)
I/flutter (29263): #13 main.<anonymous closure>.<anonymous closure> (file:///Users/Documents/my_app/integration_test/app_test.dart:29:7)
I/flutter (29263): #14 main.<anonymous closure>.<anonymous closure> (file:///Users/Documents/my_app/integration_test/app_test.dart:28:49)
I/flutter (29263): #15 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:156:29)
I/flutter (29263): <asynchronous suspension>
I/flutter (29263): <asynchronous suspension>
I/flutter (29263): (elided 3 frames from class _AssertionError and package:stack_trace)
I/flutter (29263):
I/flutter (29263): The test description was:
I/flutter (29263): Basic Home Screen Smoke test
I/flutter (29263): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (29263): (If WidgetTester.takeException is called, the above exception will be ignored. If it is not, then the above exception will be dumped when another
exception is caught by the framework or when the test ends, whichever happens first, and then the test will fail due to having not caught or expected the
exception.)
I/flutter (29263): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (29263): The following assertion was thrown running a test:
I/flutter (29263): 'package:flutter/src/foundation/binding.dart': Failed assertion: line 55 pos 12:
I/flutter (29263): '!_debugInitialized': is not true.
I/flutter (29263):
I/flutter (29263): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (29263): more information in this error message to help you determine and fix the underlying cause.
I/flutter (29263): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (29263): https://github.com/flutter/flutter/issues/new?template=2_bug.md
I/flutter (29263):
I/flutter (29263): When the exception was thrown, this was the stack:
I/flutter (29263): #2 new BindingBase (package:flutter/src/foundation/binding.dart:55:12)
I/flutter (29263): #3 new _WidgetsFlutterBinding&BindingBase&GestureBinding (package:flutter/src/widgets/binding.dart)
I/flutter (29263): #4 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding (package:flutter/src/widgets/binding.dart)
I/flutter (29263): #5 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding (package:flutter/src/widgets/binding.dart)
I/flutter (29263): #6 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding
(package:flutter/src/widgets/binding.dart)
I/flutter (29263): #7 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding
(package:flutter/src/widgets/binding.dart)
I/flutter (29263): #8 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding
(package:flutter/src/widgets/binding.dart)
I/flutter (29263): #9 new
_WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding
(package:flutter/src/widgets/binding.dart)
I/flutter (29263): #10 new WidgetsFlutterBinding (package:flutter/src/widgets/binding.dart)
I/flutter (29263): #11 new CustomImageCache (package:app/custom_image_cache.dart)
I/flutter (29263): #12 main (package:app/main_staging.dart:51:3)
I/flutter (29263): #13 main.<anonymous closure>.<anonymous closure> (file:///Users/cs/Documents/my_app/integration_test/app_test.dart:29:7)
I/flutter (29263): #14 main.<anonymous closure>.<anonymous closure> (file:///Users/cs/Documents/my_app/integration_test/app_test.dart:28:49)
I/flutter (29263): #15 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:156:29)
I/flutter (29263): <asynchronous suspension>
I/flutter (29263): <asynchronous suspension>
I/flutter (29263): (elided 3 frames from class _AssertionError and package:stack_trace)
I/flutter (29263):
The test description was:
Basic Home Screen Smoke test
═════════════════════════════════════════════════════════════════
end of failure 1
I/flutter (29881): 'package:flutter_test/src/binding.dart': Failed assertion: line 1648 pos 12: '!_expectingFrame': is not true.
I have the following files setup
test_driver/integration_driver.dart
import 'package:integration_test/integration_test_driver.dart';
Future<void> main() => integrationDriver();
integration_test/app_test.dart
import 'package:app/main_staging.dart' as stagingApp;
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group("My tests", () {
testWidgets('Basic Home Screen Smoke test', (WidgetTester tester) async {
stagingApp.main();
await tester.pumpWidget(stagingApp.MyApp());
// await Future.delayed(Duration(seconds: 1));
await tester.pumpAndSettle(Duration(seconds: 20));
});
});
}
The command I am running
flutter drive \
--flavor dev \
--driver=test_driver/integration_driver.dart \
--target=integration_test/app_test.dart
the main function has this kind of setup:
void main() async {
...
WidgetsFlutterBinding.ensureInitialized();
...
}