Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TDD in Flutter/Dart. How to reduce start up time

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

like image 916
Minsky Avatar asked Jun 20 '18 12:06

Minsky


1 Answers

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!
like image 65
Omatt Avatar answered Nov 01 '22 14:11

Omatt