集成测试时如何解决 Flutter 中请求“dart.ui”的问题
Posted
技术标签:
【中文标题】集成测试时如何解决 Flutter 中请求“dart.ui”的问题【英文标题】:How can solve requesting "dart.ui" in Flutter while Integration Testing 【发布时间】:2020-06-30 22:40:35 【问题描述】:我正在对我的登录页面进行集成测试。这是我得到的错误。我该如何解决这个错误。
C:\Users\user\androidStudioProjects\flutter_project>flutter drive --target=test_driver/app.dart 发现多个连接设备:SM J210F • 4200a590689b1400 • android-arm • Android 6.0.1 (API 23) Android SDK 为 x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27)(模拟器)使用设备 SM J210F。 启动应用程序:test_driver/app.dart build\app\outputs\apk\app.apk... 92.6s 运行 Gradle 任务 'assembleDebug'... I/flutter (5922): Observatory 收听http://127.0.0.1:54862/GeAeXgP3k4M=/
E/FlutterFcmService(5922):致命:找不到回调
I/flutter (7271):天文台监听 http://127.0.0.1:48093/UgDcJGtlUI0=/
E/FlutterFcmService(7271): 致命:找不到回调
registerResGeneratingTask 已弃用,请使用 registerGeneratedResFolders(FileCollection)
registerResGeneratingTask 已弃用,请使用 registerGeneratedResFolders(FileCollection)
registerResGeneratingTask 已弃用,请使用 registerGeneratedResFolders(FileCollection) 运行 Gradle 任务 'assembleDebug'... 95.3s √ 内置 构建\app\outputs\apk\debug\app-debug.apk。安装 build\app\outputs\apk\app.apk... 28.1s 包 安装错误:失败 [INSTALL_FAILED_INSUFFICIENT_STORAGE] 正在卸载旧版本... 正在安装 build\app\outputs\apk\app.apk... 93.1s I/flutter(8617):天文台监听 http://127.0.0.1:54916/WUrIswnOm3g=/E/FlutterFcmService(8617): 致命:找不到回调/
D:/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.13.4+2/lib/cloud_firestore.dart:8:8: 错误:未找到:'dart:ui' import 'dart:ui' show hashList;
^ /D:/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-6.0.12/lib/firebase_messaging.dart:7:8: 错误:未找到:'dart:ui' import 'dart:ui';
^ /D:/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: 错误:未找到:'dart:ui' import 'dart:ui' as ui show Paint, Path, 帆布;
/D:/flutter/packages/flutter/lib/src/material/animated_icons.dart:10:8: 错误:未找到:'dart:ui' import 'dart:ui' show lerpDouble;
^ /D:/flutter/packages/flutter/lib/src/material/app.dart:5:8: 错误:未找到:'dart:ui' import 'dart:ui' as ui;
^ /D:/flutter/packages/flutter/lib/src/material/app_bar_theme.dart:5:8: 错误:未找到:'dart:ui' import 'dart:ui' show lerpDouble;^ /D:/flutter/packages/flutter/lib/src/material/arc.dart:6:8: 错误:未找到:'dart:ui' import 'dart:ui' show lerpDouble;
^ /D:/flutter/packages/flutter/lib/src/material/bottom_app_bar_theme.dart:5:8: 错误:未找到:'dart:ui' import 'dart:ui' show lerpDouble;
^ /D:/flutter/packages/flutter/lib/src/material/bottom_sheet_theme.dart:5:8: 错误:未找到:'dart:ui' import 'dart:ui' show lerpDouble;
^ /D:/flutter/packages/flutter/lib/src/material/button_bar_theme.dart:5:8: 错误:未找到:'dart:ui' import 'dart:ui' show lerpDouble; ^
正在停止应用程序实例。驱动程序测试失败:254
我的 app_test.dart 代码
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';`
void main()
group("Flutter Auth Test", ()
final emailField = find.byValueKey("emailfield");
final passwordField = find.byValueKey("passwordfield");
final signbutton = find.byValueKey("log");
final adminPage = find.byValueKey("home");
final userPage = find.byValueKey("userp");
FlutterDriver driver;
setUpAll(()async
driver = await FlutterDriver.connect();
);
tearDownAll(()async
if(driver != null)
driver.close();
);
test("login with incorrect email and password",() async
await driver.tap(emailField);
await driver.enterText("test@gmail.com");
await driver.tap(passwordField);
await driver.enterText("test123");
await driver.tap(signbutton);
await driver.waitUntilNoTransientCallbacks();
assert(adminPage == null && userPage == null);
);
test("login admin with correct email and password",() async
await driver.tap(emailField);
await driver.enterText("madhuwanthiaah@gmail.com");
await driver.tap(passwordField);
await driver.enterText("admin123");
await driver.tap(signbutton);
assert(adminPage != null && userPage == null);
);
test("login user with correct email and password",() async
await driver.tap(emailField);
await driver.enterText("cst16029@gmail.com");
await driver.tap(passwordField);
await driver.enterText("user123");
await driver.tap(signbutton);
assert(userPage != null && adminPage == null);
);
);
【问题讨论】:
您能分享您尝试执行的测试以及您在其中使用的导入吗?您不能在集成测试中使用dart.ui
import。
我将编辑我的问题。感谢您的回复。
【参考方案1】:
我解决了更新我的包并运行的问题,
flutter drive --target=test_driver/app.dart
命令。
这个对我有用。我使用 android 模拟器进行此测试。
【讨论】:
以上是关于集成测试时如何解决 Flutter 中请求“dart.ui”的问题的主要内容,如果未能解决你的问题,请参考以下文章
我们如何在 Flutter 中为集成测试生成 json 报告?
在测试 Web 集成时,如何让“flutter drive”显示浏览器?