TDD在Flutter / Dart中。如何减少启动时间

时间:2018-06-20 12:20:32

标签: unit-testing dart tdd flutter

我尝试在Dart中针对Flutter应用程序的业务逻辑进行测试驱动开发(TDD)。对于快速的TDD周期,运行测试的启动时间会有些慢。在我的机器上大约需要4-5秒。

我正在使用package:test / test.dart',因此无需将应用程序部署到设备上,并且测试可以在Dart VM上本地运行。测试本身运行很快。

使用Java的JUnit和本地Java VM开发Android原生应用程序时,启动时间要短于1秒。

有没有办法使Dart中的单元测试的启动时间也这么快? (无需购买速度更快的物理机器)。

编辑: 我的Dart版本:

  • Flutter Doctor -v:2.0.0-dev.54.0.flutter-46ab040e58
  • Dart插件使用: 2.0.0-edge.c080951d45e79cd25df98036c4be835b284a269c并且在我的Flutter安装中:C:\ flutter \ bin \ cache \ dart-sdk

Dart测试位于Flutter项目中。我可以通过右键单击带有测试的文件来启动Android Studio中的Dart测试,或者只使用IDE中的“>”运行测试按钮。然后,Android Studio会生成一个运行配置,因此我可以使用键盘快捷键快速启动它。

enter image description here

2 个答案:

答案 0 :(得分:2)

我最近尝试运行一个示例测试(使用 Flutter 演示应用程序),通过终端运行 flutter test 会立即初始化测试。

flutter test via terminal

但是,当通过 UI 运行测试时,我得到了类似的启动时间(大约 4 秒)。

flutter test through UI

我尝试深入研究设置,但似乎没有任何配置可以修改,以使测试的初始化速度比我们目前的要快。

这是我的颤振医生供参考。

[✓] Flutter (Channel master, 1.26.0-2.0.pre.281, on macOS 11.1 20C69 darwin-x64)
    • Flutter version 1.26.0-2.0.pre.281
    • Framework revision 4d5db88998 (2 weeks ago), 2021-01-11 10:29:26 -0800
    • Engine revision d5cacaa3a6
    • Dart version 2.12.0 (build 2.12.0-211.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Platform android-30, 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_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.0.1, Build version 12A7300
    • CocoaPods version 1.10.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      ? https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      ? https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

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

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 88.0.4324.96

• No issues found!

答案 1 :(得分:0)

这个方法非常适合我:

1. flutter run --profile --cache-sksl

2. Press M at the command line of flutter run to write the captured SkSL shaders into a file named something like flutter_01.sksl.json.

3. Build the app with SkSL warm-up using the following, as appropriate:

Android:
flutter build apk --bundle-sksl-path flutter_01.sksl.json
or
flutter build appbundle --bundle-sksl-path flutter_01.sksl.json

iOS:
flutter build ios --bundle-sksl-path flutter_01.sksl.json

For more information, visit: https://flutter.dev/docs/perf/rendering/shader