'!_debugInitialized':在运行Flutter集成测试时,

htrmnn0y  于 2023-03-31  发布在  Flutter
关注(0)|答案(1)|浏览(245)

我尝试运行一个基本的flutter集成测试来调用我的主应用程序小部件,但失败了。我遵循了官方文档[https://docs.flutter.dev/testing/integration-tests]中描述的方法
以下是完整的堆栈跟踪:

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.

我设置了以下文件
测试驱动程序/集成驱动程序.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));
    });
  });
}

我正在运行的命令

flutter drive \
  --flavor dev \
  --driver=test_driver/integration_driver.dart \
  --target=integration_test/app_test.dart

main函数有这样的设置:

void main() async {
  ...
  WidgetsFlutterBinding.ensureInitialized();
  ...
}
guykilcj

guykilcj1#

在test_driver/integration_driver.dart中添加IntegrationTestWidgetsFlutterBinding.ensureInitialized();

import 'package:integration_test/integration_test.dart';
import 'package:integration_test/integration_test_driver.dart';

Future<void> main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  return integrationDriver();
}

相关问题