gpt4 book ai didi

android - Flutter 应用程序在使用 flutter_driver 运行时无法加载 Json 文件

转载 作者:行者123 更新时间:2023-11-29 11:26:45 24 4
gpt4 key购买 nike

我正在尝试设置我的 Flutter 应用程序以使用 flutter_driver 和集成测试自动截屏,但该应用程序卡在了它应该等待 *.json 文件的 future 的位置。< br/>有人知道如何解决吗?

重现步骤

  1. 设置一个需要读取 Json 文件的应用程序(我使用了这个方法:String myJson =
    await rootBundle.loadString('my_resources/myjson.json');
  2. 设置 flutter_driver 测试:

App.dart:

import 'package:flutter_driver/driver_extension.dart';
import 'package:flutter_project/main.dart' as app;

void main() {
// This line enables the extension.
enableFlutterDriverExtension();

// Call the `main()` function of the app, or call `runApp` with
// any widget you are interested in testing.
app.main();
}

App_test.dart:

import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

void main() {
group('MyApp', () {
FlutterDriver driver;

setUpAll(() async {
driver = await FlutterDriver.connect();
});

// Close the connection to the driver after the tests have completed.
tearDownAll(() async {
if (driver != null) {
driver.close();
}
});
});
}
  1. 使用 flutter drive --target=test_driver/app.dart 运行测试

在我的例子中,应用程序停留在等待来自 1.*.json 文件的 future 使用常规的 flutter run 命令一切正常。

flutter doctor -v

[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.14.6 18G95, locale de-DE)
• Flutter version 1.9.1+hotfix.2 at /Users/patrick/Development/flutter
• Framework revision 2d2a1ffec9 (2 weeks ago), 2019-09-06 18:39:49 -0700
• Engine revision b863200c37
• Dart version 2.5.0


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/patrick/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.3, Build version 10G8
• CocoaPods version 1.7.5

[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 39.0.3
• Dart plugin version 191.8423
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.38.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.4.1

[✓] Connected device (2 available)
• iPhone 7 • 5E5C912E-EA1D-438B-B5C5-E963D4BF9B33 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)
• iPhone Xʀ • EE0825D6-B8B4-4010-B954-CC913953F5D4 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)

• No issues found!

有人对此有解决方案吗?我要导入的 *.json 是一个配置文件,因此导入它对于我来说是顺利运行的关键。真的很高兴有任何解决方法。

最佳答案

Flutter GitHub 上有一个 Unresolved 问题。看来 VM 有问题,Flutter Driver 中有隔离。

查看此评论 https://github.com/flutter/flutter/issues/30641#issuecomment-524868136它有一个指向 Flutter 分支的链接,其中包含一个测试示例(此处为 https://github.com/vishna/flutter/commit/2f858fc334fc2f43b92c318d02bdbf1ad0984033 ),该示例在过去的时间里为我解决了此类问题

此外,也许值得分享您的源代码,以便人们可以运行/调试等。

关于android - Flutter 应用程序在使用 flutter_driver 运行时无法加载 Json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58077550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com