Skip to content

Make tests compile and run faster #69429

Open

Description

@HerrNiklasRaab

Use case

According to flutter.dev one of the things flutter aims at is fast development. I think being able to develop in a TDD workflow contributes to this goal.

In our case, we have suite about 500 tests, consisting of unit and widget tests. In order to facilitate a real TDD workflow, all the tests should run very fast. There are some sources that suggest a maximum executing time of less than 10s: https://blog.ploeh.dk/2012/05/24/TDDtestsuitesshouldrunin10secondsorless/#:~:text=The%20test%20suite%20you%20work,be%20faster%20than%2010%20milliseconds.

Currently, our test suite is executing in about 2min, which makes the TDD approach very hard, because it disrupts your workflow (better described in the article).

Proposal

The aim of this ticket is more to collect all the tickets, that would contribute to a better TDD experience. So please add additional things that prevent you from a good TDD experience.

Live Unit Testing

#4719
Dart-Code/Dart-Code#2878

Improve Performance of Tests

#17130
dart-lang/sdk#32953

Hot Reload for Unit Tests

#25973
https://github.com/szotp/hottie/

Please consider 👍 this and linked tickets if you thing this is important.

Activity

  1. pedromassangocode commented on Nov 2, 2020

    @pedromassangocode

    Hi @HerrNiklasRaab
    I looked at the link you posted an I got this piece:

    That test suite doesn't need to be the same as is running on your CI server. It could be a subset of tests. That's OK. The TDD suite may just be part of your Test Pyramid.

    I'm wondering if you are running all the tests of the project or just a subset of tests related to the [new] test you are adding?

    I personally think that the duration of tests will always depend on the numbers of tests you are running and we can't just make 10.000+ tests to run in 10 seconds. As your tests increase the time will increase as well.

  2. added
    in triagePresently being triaged by the triage team
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 2, 2020
  3. HerrNiklasRaab commented on Nov 2, 2020

    @HerrNiklasRaab
    Author

    Hey @pedromassangocode,

    thanks for your response. Sure if the project grows very much, at some point you will need to split it into multiple test suits. But currently, we have 500 tests, who take about 2min. This I think is definitely too long.

    I'm wondering if you are running all the tests of the project or just a subset of tests related to the [new] test you are adding?

    Currently, we are running the tests of the whole project.

    Maybe we can keep this ticket open to track the experience from the point of view of a TDD developer.

    Best regards,

    Niklas

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 2, 2020
  5. pedromassangocode commented on Nov 2, 2020

    @pedromassangocode

    I'm still not sure what can be done here so will leave this opened for the right people to handle it.
    Cc @Hixie @HansMuller

  6. added
    a: tests"flutter test", flutter_test, or one of our tests
    frameworkflutter/packages/flutter repository. See also f: labels.
    perf: speedPerformance issues related to (mostly rendering) speed
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Nov 2, 2020
  7. Hixie commented on Nov 2, 2020

    @Hixie
    Contributor

    @HerrNiklasRaab We will need more information to help here, for example, some profiles and traces of running the tests in question to see where the time is going.

    It would also be good to have an estimate of how long each test should take. Is it reasonable for a test to take 250ms on average? Or should it be faster? Also, it would be useful to know whether you get different performance by changing the -j option to change how many cores are being used.

  8. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 3, 2020
  9. HerrNiklasRaab commented on Nov 12, 2020

    @HerrNiklasRaab
    Author

    Hi @Hixie,

    Thanks for your answer.

    I think the most important part of unit tests is that they run fast, with fast I mean very fast. As soon as they are so slow that you don't run them every few minutes they turn into a burden. With fast tests your workflow looks like:

    With fast tests:

    1. Run all tests
    2. Change one thing
    3. Run all tests → When it fails you know exactly what which change caused the failure

    With slow tests

    1. Run all tests
    2. You change multiple things because tests are slow
    3. You end up with multiple test failing, you need to start debugging, find the changes that caused the failure

    My argument is, that the faster the tests run, the shorter this loop is, the more efficient you are developing, because your mind only needs to concentrate on one thing. You never need to debug.

    Having very fast tests is crucial. That's why I think 250ms is way too long (no offense). I worked on projects with 5ms per test. This means you can have 2000 tests in your suite and they are still running in 10s.

    With 250ms you can only execute 40 tests in 10s. This means you either run them not as often, (consequences described above) or you need to spend a lot of time thinking which test to run. This is very difficult (because you don't know which tests are affected by your change), time-consuming and there is no support in the IDE for running only a subset of tests.


    I tried it with "-j", and it yielded a slight improvement. I have also the logs when running with "-v" but I am not sure if this is what you meant with "some profiles and traces of running the tests".

    Verbose logs: text-verbose.txt.zip

    image

    Thanks very much and very interested in your response,

    Niklas

    PS: If improving the testspeed by this ammount is not possible due to technical reasons. Maybe it might be worth having a look at this project, which yields the hot reload: https://github.com/szotp/hottie/

  10. 16 remaining items

  11. svarlet commented on Aug 31, 2021

    @svarlet

    Agreed, until a real change is visible in the stable channel, It feels odd to "close" the issue.

  12. jakemac53 commented on Aug 31, 2021

    @jakemac53
    Contributor

    Ya sorry I hadn't read the full context of the issue :). The change in the test package is very specifically geared towards regular Dart tests also, and has no effect on flutter tests. It should provide a dramatic improvement for regular Dart tests though 👍 .

    I believe that flutter tests are already optimized using similar means (it is what inspired the VM test optimization). So if you are experiencing slow flutter tests I would look at the flutter test platform code and/or flutter test utilities.

  13. Hixie commented on Sep 1, 2021

    @Hixie
    Contributor

    We're nowhere near tests running fast even on master (on my 20 core machine, using all 20 cores, it takes SEVEN SECONDS for flutter test to even begin to run the first test in the flutter package, for example, and the whole test suite takes 3m20s, which is about 0.55ms per test line, which seems really high!), so I agree that this bug shouldn't be closed.

    That said, it is our policy to close issues once they are fixed on master, we don't leave bugs open until they are fixed on stable. This is because otherwise we would be flooded with literally thousands of open bugs that are not actionable, whose close date would be months later. The GitHub issues are our development bug database and they therefore track master, not stable.

  14. orestesgaolin commented on Jan 17, 2022

    @orestesgaolin
    Contributor

    Just wanted to add that the most problematic for us is the performance of coverage reporting tests on CI. For example a suite of 1400 tests takes over 20 minutes to finish. In other words it's about 1 second per test. The same process but without --coverage takes around 6 minutes. It doesn't help much to cache build artifacts or dependencies. This really slows down the loop when doing the code reviews. We're looking into sharding the tests between multiple parallel runs, but in practice we wish it was just faster to run tests with coverage.

  15. Hixie commented on Jan 19, 2022

    @Hixie
    Contributor

    Coverage being slow is a separate issue (it requires changes to different parts of the codebase). We've made significant improvements over the past year to the coverage (mostly around accuracy, but also performance), but if you are still running into performance issues please file a bug specifically on that. If you have specific tests we can run that demonstrate the problem that is ideal (the Flutter framework tests are probably a good place to start if your project isn't open source itself).

  16. cyberalt1 commented on Mar 3, 2025

    @cyberalt1
  17. szotp commented on Nov 27, 2025

    @szotp

    Coming back to this topic as I have found something pretty cool. You can run any test file via regular flutter command using

    flutter run -d flutter-tester my_test.dart

    The best part is: it's normal flutter execution with hot restart & roload, but test execute as usual.

    Making tests run on every reload was a bit tricky but I got a demo working: https://github.com/szotp/hottie_next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsc: performanceRelates to speed or footprint issues (see "perf:" labels)c: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.perf: speedPerformance issues related to (mostly rendering) speedteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions