25

I try to do Test-Driven Development (TDD) in Dart for the business logic of apps with Flutter. The startup time for running the test feels a little bit slow for fast TDD cycles. It is around 4-5 seconds on my machine.

I am using the package:test/test.dart, so there is no need to deploy the app onto the device and the tests can run locally on the Dart VM. The tests themselves run fast.

While developing Android native apps with Java's JUnit and the local Java VM the startup time was much faster < 1sec.

Is there a way to get the start-up time for unit testing in Dart that fast too? (Without buying a much faster physical machine).

Edit: My Dart versions:

  • Flutter doctor -v: 2.0.0-dev.54.0.flutter-46ab040e58
  • The Dart Plugin uses: 2.0.0-edge.c080951d45e79cd25df98036c4be835b284a269c and is in my flutter installation: C:\flutter\bin\cache\dart-sdk

The Dart tests are inside a Flutter project. I start the Dart tests in Android Studio via right-clicking a file with a test or just use the ">" run test buttons in the IDE. Android Studio then generates a run config, so I can start it with keyboard shortcuts fast.

enter image description here

Omar Sherif
  • 649
  • 9
  • 26
Minsky
  • 2,106
  • 28
  • 31
  • 3
    How are you running the tests? What you describe seems to be unrelated to Flutter. Perhaps you are writing Dart tests that are stored in a Flutter project. I assume you are using `pub run test`, right? – Günter Zöchbauer Jun 20 '18 at 12:24
  • 2
    What Dart version are you using? – Günter Zöchbauer Jun 20 '18 at 12:24
  • @GünterZöchbauer Yes, the dart tests are inside a Flutter project. I updated my post with the details you requested. – Minsky Jun 20 '18 at 12:40
  • 2
    If you use the context menu it depends on what Dart SDK the `Dart SDK path` in the IntelliJ Dart plugin settings points to if you use `pub run test` or `flutter test`. – Günter Zöchbauer Jun 20 '18 at 12:49
  • What SDK path is configured in the Dart plugin? – Günter Zöchbauer Jun 20 '18 at 13:01
  • I think it is: C:\flutter\bin\cache\dart-sdk . As part of the flutter sdk. Info from Android Studio->Settings->Languages&Frameworks&Dart->Dart SDK path. – Minsky Jun 20 '18 at 13:03
  • 2
    Would be great to know for sure. But that means it uses `flutter test`. I don't know how to make it faster, but I'm quite sure the Dart team will work hard on that. The compiler toolchain has changed a lot from Dart 1 to Dart 2 and after the Dart 2 functionality is stable they will spend more time on performance optimizations. That there is lots of room for improvements was mentioned several times from Dart members on GitHub issue comments. – Günter Zöchbauer Jun 20 '18 at 13:06
  • @GünterZöchbauer I see. Thank you. I will try to use pub run test, perhaps this works, as a last try for now. Else we just have to wait :) – Minsky Jun 20 '18 at 13:07
  • It should work if you don't use `widgetTester` and the test or code you test doesn't depend on `flutter:ui`. – Günter Zöchbauer Jun 20 '18 at 13:10
  • Looks like I have to setup a normal Dart SDK for it. 'pub run' test needs a pubspec.yaml in my OS user directory (Windows here). Running 'pub get' tells me because my project depends on flutter_test, version solving failed. I will call it a day for now and try it later. Thanks again. – Minsky Jun 20 '18 at 13:39
  • Because of " package:test/test.dart', so there is no need to deploy the app onto the device and the tests can run locally on the Dart VM" I assumed that is your setup anyway. I thought someone mentioned that this can be done this way, but I haven't tried it myself so don't know for sure. – Günter Zöchbauer Jun 20 '18 at 15:11
  • I setup a minimal configuration. Just a Dart 2 SDK and a simple test case file. There I ran "dart myunittest.dart" The test runs fast through, but the startup time was the same as in my original post. Looks like as of right now it cannot be faster. – Minsky Jun 26 '18 at 05:41
  • 2
    I'm sure they are working on it and will continue improving after Dart 2 is released. The whole parser-compiler toolchain was rebuilt for Dart 2. First they are focusing at feature completeness and then at performance. – Günter Zöchbauer Jun 26 '18 at 05:44
  • 1
    @GünterZöchbauer. Yes thank you, no problem right now, I will wait patiently and still continue useing Dart/Flutter now. – Minsky Jun 26 '18 at 07:14
  • An example https://github.com/flutter/flutter/pull/18810 ;-) (just stumbled upon it) – Günter Zöchbauer Jun 26 '18 at 07:34
  • looks promising, thx :) – Minsky Jun 26 '18 at 10:49

3 Answers3

3

I've tried running a sample test (using the Flutter demo app) recently, running flutter test through the terminal initializes the test in an instant.

flutter test via terminal

However, I got similar startup time (around 4 seconds) when the tests were run through the UI.

flutter test through UI

I tried digging into the settings and there doesn't seem to be any config that we can modify to make the tests initialize faster compared to what we have at present.

Here's my flutter doctor for reference.

[✓] 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!
Omatt
  • 8,564
  • 2
  • 42
  • 144
0

Try your code in vs code with extended terminal

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 25 '23 at 08:23
-1

This method works perfectly for me:

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
QOU
  • 5
  • 2
  • 6