集成测试迁移后无法通过启动画面

时间:2021-05-30 15:40:34

标签: flutter integration-testing splash-screen

我的集成测试正在使用 flutter_driver,但在 the docs 之后迁移到 integration_test 后,我​​无法通过启动画面。

下面是一个简单的测试。如果不使用 sleep,我永远不会通过 Test starting... 屏幕,因为其他人发现 here。使用 sleep 测试通过 Test starting... 但卡在我的初始屏幕上。不确定它是否相关,但我的身份验证屏幕在我的启动屏幕之后。

import 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../lib/main.dart' as app;

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  testWidgets('verify users', (WidgetTester tester) async {
    app.main();

    sleep(const Duration(seconds: 10));

    await tester.pumpAndSettle();

    final Finder menuButtonFinder = find.byKey(const Key('kKeyButtonMenu'));

    expect(menuButtonFinder, findsOneWidget);
  });
}

下面是显示失败的输出

PS C:\projects\dream_app> flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart       
Running "flutter pub get" in dream_app...                        1,128ms
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                        29.9s
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...                861ms
D/EGL_emulation(16572): eglMakeCurrent: 0xda965820: ver 2 0 (tinfo 0xc3357610)
D/EGL_emulation(16572): eglMakeCurrent: 0xddd1ad20: ver 2 0 (tinfo 0xddd0fc70)
D/eglCodecCommon(16572): setVertexArrayObject: set vao to 0 (0) 1 0
I/OpenGLRenderer(16572): Davey! duration=1837ms; Flags=1, IntendedVsync=580073648796040, Vsync=580073665462706,
OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=580073681834600, AnimationStart=580073681923600,
PerformTraversalsStart=580073681982400, DrawStart=580075339090900, SyncQueued=580075340979900, SyncStart=580075354420900,  
IssueDrawCommandsStart=580075355228300, SwapBuffers=580075391296000, FrameCompleted=580075499793800,
DequeueBufferDuration=19391000, QueueBufferDuration=499000,
I/Choreographer(16572): Skipped 110 frames!  The application may be doing too much work on its main thread.
VMServiceFlutterDriver: Connecting to Flutter application at http://127.0.0.1:54327/W14R71Jsq2c=/
VMServiceFlutterDriver: Isolate found with number: 3967110223154191
VMServiceFlutterDriver: Isolate is paused at start.
VMServiceFlutterDriver: Attempting to resume isolate
D/EGL_emulation(16572): eglMakeCurrent: 0xda965820: ver 2 0 (tinfo 0xc3357610)
D/eglCodecCommon(16572): setVertexArrayObject: set vao to 0 (0) 1 0
I/flutter (16572): 00:00 +0: verify users
VMServiceFlutterDriver: Connected to Flutter application.
I/lytics.dreamap(16572): The ClassLoaderContext is a special shared library.
I/chatty  (16572): uid=10179(com.dreamalytics.dreamapp) identical 1 line
I/lytics.dreamap(16572): The ClassLoaderContext is a special shared library.
I/lytics.dreamap(16572): Waiting for a blocking GC ClassLinker
I/lytics.dreamap(16572): WaitForGcToComplete blocked ClassLinker on ProfileSaver for 12.908ms
I/DynamiteModule(16572): Considering local module com.google.android.gms.ads.dynamite:0 and remote module
com.google.android.gms.ads.dynamite:211512000
I/DynamiteModule(16572): Selected remote version of com.google.android.gms.ads.dynamite, version >= 211512000
D/DynamitePackage(16572): Instantiated singleton DynamitePackage.
D/DynamitePackage(16572): Instantiating com.google.android.gms.ads.ChimeraMobileAdsSettingManagerCreatorImpl
W/lytics.dreamap(16572): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist,
linking, allowed)
W/lytics.dreamap(16572): Accessing hidden method
Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)   
W/ConnectionStatusConfig(16572): Dynamic lookup for intent failed for action: com.google.android.gms.leibniz.events.service.STARTE/GmsClient(16572): unable to connect to service: com.google.android.gms.leibniz.events.service.START on com.google.android.gms
W/lytics.dreamap(16572): Accessing hidden method
Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)   
I/WebViewFactory(16572): Loading com.google.android.webview version 74.0.3729.185 (code 373018518)
I/lytics.dreamap(16572): The ClassLoaderContext is a special shared library.
I/lytics.dreamap(16572): The ClassLoaderContext is a special shared library.
I/cr_LibraryLoader(16572): Time to load native libraries: 12 ms (timestamps 8336-8348)
I/chromium(16572): [INFO:library_loader_hooks.cc(50)] Chromium logging enabled: level = 0, default verbosity = 0
I/cr_LibraryLoader(16572): Expected native library version number "74.0.3729.185", actual native library version number
"74.0.3729.185"
W/cr_ChildProcLH(16572): Create a new ChildConnectionAllocator with package name = com.google.android.webview, sandboxed = true
W/lytics.dreamap(16572): Accessing hidden method
Landroid/content/Context;->bindServiceAsUser(Landroid/content/Intent;Landroid/content/ServiceConnection;ILandroid/os/Handler;Landroid/os/UserHandle;)Z (greylist, reflection, allowed)
I/cr_BrowserStartup(16572): Initializing chromium process, singleProcess=false
E/chromium(16572): [ERROR:filesystem_posix.cc(89)] stat /data/user/0/com.dreamalytics.dreamapp/cache/WebView/Crashpad: No such
file or directory (2)
E/chromium(16572): [ERROR:filesystem_posix.cc(62)] mkdir /data/user/0/com.dreamalytics.dreamapp/cache/WebView/Crashpad: No such
file or directory (2)
W/lytics.dreamap(16572): Accessing hidden method
Landroid/view/textclassifier/logging/SmartSelectionEventTracker;-><init>(Landroid/content/Context;I)V (greylist, reflection,     
allowed)
W/lytics.dreamap(16572): Accessing hidden method
Landroid/view/textclassifier/logging/SmartSelectionEventTracker;->logEvent(Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;)V (greylist, reflection, allowed)
W/lytics.dreamap(16572): Accessing hidden method
Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionStarted(I)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection, allowed)
W/lytics.dreamap(16572): Accessing hidden method
Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(II)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection, allowed)
W/lytics.dreamap(16572): Accessing hidden method
Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection,      
allowed)
W/lytics.dreamap(16572): Accessing hidden method
Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextSelection;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection, allowed)  
W/lytics.dreamap(16572): Accessing hidden method
Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(III)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection, allowed)
W/lytics.dreamap(16572): Accessing hidden method
Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(IIILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection,       
allowed)
W/cr_media(16572): Requires BLUETOOTH permission
D/HostConnection(16572): HostConnection::get() New Host Connection established 0xb4191340, tid 16729
D/HostConnection(16572): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem
ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands
ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21    
ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8  
ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr
ANDROID_EMU_gles_max_version_2
E/chromium(16572): [ERROR:gl_surface_egl.cc(342)] eglChooseConfig failed with error EGL_SUCCESS
W/lytics.dreamap(16572): Accessing hidden method
Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)   
I/Choreographer(16572): Skipped 35 frames!  The application may be doing too much work on its main thread.
I/lytics.dreamap(16572): NativeAlloc concurrent copying GC freed 14077(1257KB) AllocSpace objects, 6(232KB) LOS objects, 49%
free, 3486KB/6972KB, paused 1.983ms total 111.546ms
I/OpenGLRenderer(16572): Davey! duration=953ms; Flags=0, IntendedVsync=580078056495135, Vsync=580078639828445,
OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=580078641823200, AnimationStart=580078641880200,      
PerformTraversalsStart=580078641955600, DrawStart=580078642163700, SyncQueued=580078642249900, SyncStart=580078642789500,        
IssueDrawCommandsStart=580078642831900, SwapBuffers=580078653158500, FrameCompleted=580079010104200,
DequeueBufferDuration=274000, QueueBufferDuration=474000,
D/eglCodecCommon(16572): setVertexArrayObject: set vao to 0 (0) 0 0
D/EGL_emulation(16572): eglCreateContext: 0xe5e667c0: maj 2 min 0 rcv 2
D/EGL_emulation(16572): eglMakeCurrent: 0xe5e667c0: ver 2 0 (tinfo 0xb41ed380)
E/chromium(16572): [ERROR:gl_surface_egl.cc(342)] eglChooseConfig failed with error EGL_SUCCESS
I/VideoCapabilities(16572): Unsupported profile 4 for video/mp4v-es
W/cr_MediaCodecUtil(16572): HW encoder for video/avc is not available on this device.
D/eglCodecCommon(16572): setVertexArrayObject: set vao to 0 (0) 0 0
D/EGL_emulation(16572): eglCreateContext: 0xe5eed240: maj 2 min 0 rcv 2
D/EGL_emulation(16572): eglMakeCurrent: 0xe5eed240: ver 2 0 (tinfo 0xb41ed380)
D/eglCodecCommon(16572): setVertexArrayObject: set vao to 1 (1) 0 0
W/ConnectionTracker(16572): Exception thrown while unbinding
W/ConnectionTracker(16572): java.lang.IllegalArgumentException: Service not registered:
com.google.android.gms.measurement.internal.zzjj@479ea95
W/ConnectionTracker(16572):     at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1751)
W/ConnectionTracker(16572):     at android.app.ContextImpl.unbindService(ContextImpl.java:1776)
W/ConnectionTracker(16572):     at android.content.ContextWrapper.unbindService(ContextWrapper.java:741)
W/ConnectionTracker(16572):     at
com.google.android.gms.common.stats.ConnectionTracker.zza(com.google.android.gms:play-services-basement@@17.3.0:55)
W/ConnectionTracker(16572):     at
com.google.android.gms.common.stats.ConnectionTracker.unbindService(com.google.android.gms:play-services-basement@@17.3.0:50)    
W/ConnectionTracker(16572):     at
com.google.android.gms.measurement.internal.zzjk.zzF(com.google.android.gms:play-services-measurement-impl@@19.0.0:6)
W/ConnectionTracker(16572):     at
com.google.android.gms.measurement.internal.zziu.zza(com.google.android.gms:play-services-measurement-impl@@19.0.0:5)
W/ConnectionTracker(16572):     at
com.google.android.gms.measurement.internal.zzak.run(com.google.android.gms:play-services-measurement-impl@@19.0.0:5)
W/ConnectionTracker(16572):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
W/ConnectionTracker(16572):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/ConnectionTracker(16572):     at
com.google.android.gms.measurement.internal.zzfq.run(com.google.android.gms:play-services-measurement-impl@@19.0.0:6)
W/lytics.dreamap(16572): Accessing hidden method
Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)   
I/flutter (16572): (The following exception is now available via WidgetTester.takeException:)
I/flutter (16572): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (16572): The following TestFailure object was thrown running a test:
I/flutter (16572):   Expected: exactly one matching node in the widget tree
I/flutter (16572):   Actual: _KeyFinder:<zero widgets with key [<'kKeyButtonMenu'>] (ignoring offstage widgets)>
I/flutter (16572):    Which: means none were found but one was expected
I/flutter (16572):
I/flutter (16572): When the exception was thrown, this was the stack:
I/flutter (16572): #4      main.<anonymous closure> (file:///C:/projects/dream_app/integration_test/app_test.dart:19:5)
I/flutter (16572): <asynchronous suspension>
I/flutter (16572): <asynchronous suspension>
I/flutter (16572): (elided one frame from package:stack_trace)
I/flutter (16572): ...
I/flutter (16572):
I/flutter (16572): This was caught by the test expectation on the following line:
I/flutter (16572):   file:///C:/projects/dream_app/integration_test/app_test.dart line 19
I/flutter (16572): The test description was:
I/flutter (16572):   verify users
I/flutter (16572): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (16572): (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 (16572): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (16572): The following TestFailure object was thrown running a test:
I/flutter (16572):   Expected: exactly one matching node in the widget tree
I/flutter (16572):   Actual: _KeyFinder:<zero widgets with key [<'kKeyButtonMenu'>] (ignoring offstage widgets)>
I/flutter (16572):    Which: means none were found but one was expected
I/flutter (16572):
I/flutter (16572): When the exception was thrown, this was the stack:
I/flutter (16572): #4      main.<anonymous closure> (file:///C:/projects/dream_app/integration_test/app_test.dart:19:5)
I/flutter (16572): <asynchronous suspension>
I/flutter (16572): <asynchronous suspension>
I/flutter (16572): (elided one frame from package:stack_trace)
I/flutter (16572): ...
I/flutter (16572):
I/flutter (16572): This was caught by the test expectation on the following line:
I/flutter (16572):   file:///C:/projects/dream_app/integration_test/app_test.dart line 19
I/flutter (16572): The test description was:
I/flutter (16572):   verify users
I/flutter (16572): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (16572): 00:11 +0: verify users [E]
I/flutter (16572):   Test failed. See exception logs above.
I/flutter (16572):   The test description was: verify users
I/flutter (16572):   
I/flutter (16572): 00:11 +0 -1: (tearDownAll)
Failure Details:
Failure in method: verify users
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═════════════════
The following TestFailure object was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: _KeyFinder:<zero widgets with key [<'kKeyButtonMenu'>]
(ignoring offstage widgets)>
Which: means none were found but one was expected

When the exception was thrown, this was the stack:
#4      main.<anonymous closure> (file:///C:/projects/dream_app/integration_test/app_test.dart:19:5)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)

This was caught by the test expectation on the following line:
file:///C:/projects/dream_app/integration_test/app_test.dart line 19
The test description was:
verify users
═════════════════════════════════════════════════════════════════

end of failure 1

2 个答案:

答案 0 :(得分:0)

这对你有用吗?

import 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../lib/main.dart' as app;

void main() {
  // Changing the `utilityPolicy`. Credits to: https://stackoverflow.com/a/68099497/8358501
  final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;
  binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;

  testWidgets('verify users', (WidgetTester tester) async {
    app.main();

    sleep(const Duration(seconds: 10));

    await tester.pumpAndSettle();

    final Finder menuButtonFinder = find.byKey(const Key('kKeyButtonMenu'));

    expect(menuButtonFinder, findsOneWidget);
  });
}

答案 1 :(得分:0)

除了 Nils 建议的之外,我还必须在运行 pumpAndSettle(Duration(seconds: 3)) 后添加 pump(Duration(seconds: 3)) 或仅添加 app.main()

我认为 pumpAndSettle(Duration)sleep(Duration)pumpAndSettle() 相同,但使用后一个命令,我的应用程序卡在启动屏幕上。

所以,对我来说,工作代码是:

import 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../lib/main.dart' as app;

void main() {
  final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;
  binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;

  testWidgets('verify users', (WidgetTester tester) async {
    app.main();
    await tester.pumpAndSettle(Duration(seconds: 3));

    final Finder menuButtonFinder = find.byKey(const Key('kKeyButtonMenu'));

    expect(menuButtonFinder, findsOneWidget);
  });
}
相关问题