我正在尝试通过此链接对 image_picker 进行 e2e 测试的解决方案如何在 Flutter Driver 中测试 ImagePicker?
void main() {
enableFlutterDriverExtension();
const MethodChannel channel =
MethodChannel('plugins.flutter.io/image_picker');
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
ByteData data = await rootBundle.load('images/sample.png');
Uint8List bytes = data.buffer.asUint8List();
Directory tempDir = await getTemporaryDirectory();
File file = await File(
'${tempDir.path}/tmp.tmp',
).writeAsBytes(bytes);
print(file.path);
return file.path;
});
});
app.main();
}
我的主要测试文件是完全一样的。问题是,当我enableFlutterDriverExtension();
在开始后立即使用测试时,完成了所有测试通过的信息,没有在模拟器上模拟步骤,并在每一步后将所有信息打印到控制台。在控制台中我得到
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter_driver/src/extension/extension.dart': Failed assertion: line 222 pos 10:
'WidgetsBinding.instance == null': is not true.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:47:61)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
#2 enableFlutterDriverExtension (package:flutter_driver/src/extension/extension.dart:222:10)
#3 main
没有 enableFlutterDriverExtension(); 当我尝试调用 image_picker 时测试失败。有错误
flutter: 'package:flutter_test/src/binding.dart': Failed assertion: line 775 pos 14: '_pendingExceptionDetails != null': A test overrode FlutterError.onError
but either failed to return it to its original state, or had unexpected additional errors that it could not handle. Typically, this is caused by using expect()
before restoring FlutterError.onError.
flutter: dart:core-patch/errors_patch.dart 47:61 _AssertionError._doThrowNew
enableFlutterDriverExtension() 究竟是什么?做?没有测试 image_picker 并且这个 enableFlutterDriverExtension() 测试工作正常。还有其他测试 image_picker 的解决方案吗?