Skip to content

The flutter test command should require a flutter_test or test_api dependency (and check for it). #91107

Open

Description

@jakemac53

Use case

The flutter test command itself is built with a certain version of the test package (whatever is pinned in the repo at the time the SDK was published). If a user is only using the regular test package, then there is nothing to ensure that the version is compatible with that of the flutter test command.

See #91059 as an example failure.

Proposal

The flutter test command should check for a dependency on flutter_test, and fail (or at least warn) if one does not exist. This package pins the test_api package to a compatible version, solving the issue.

Activity

  1. added
    a: tests"flutter test", flutter_test, or one of our tests
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Oct 1, 2021
  2. Hixie commented on Oct 1, 2021

    @Hixie
    Contributor

    Would it make sense to test for the right version of test_api, rather than flutter_test? (In the message we should suggest depending on flutter_test, certainly, but I feel like if someone is doing the dance to point to the right test_api version that should work too; they don't have to use flutter_test with flutter test.)

  3. jakemac53 commented on Oct 1, 2021

    @jakemac53
    ContributorAuthor

    I would probably just depend on flutter_test, as it will take into account all the possible deps and make sure they are compatible. Being an sdk dependency it is already downloaded and essentially free (assuming it's a dev dependency).

    In practice it's likely that just enforcing test_api is compatible would fix most issues though.

  4. Hixie commented on Oct 1, 2021

    @Hixie
    Contributor

    I guess asking for it to be in the pubspec.yaml as a dev dependency is probably ok. It doesn't require actually importing it.

  5. jakemac53 commented on Mar 23, 2023

    @jakemac53
    ContributorAuthor

    Note dart-lang/test#1977, this is another good example of why we should be requiring this dependency even if people don't use the package as an import.

  6. natebosch commented on Mar 23, 2023

    @natebosch
    Contributor

    This is also what webdev does - it checks for appropriate versions of packages like build_web_compilers.

    If any tool is going to operate with packages from the pub solve, but not be installed with that same pub solve, it should validate any assumptions it makes about how it can operate with those packages.

    From the user standpoint a dev_dependency on the SDK vendored version of flutter_test is a far superior UX to a pinned dependency on test_api. With the former they can be compatible across Flutter SDK releases.

  7. polina-c commented on Mar 23, 2023

    @polina-c
    Contributor

    DevTools just faced the issue

  8. guyluz11 commented on Mar 24, 2023

    @guyluz11

    Not sure if it was mentiond already but wanted to point out that in the documentation of flutter it is written that

    Add the test or flutter_test dependency.

    https://docs.flutter.dev/cookbook/testing/unit/introduction

  9. jakemac53 commented on Mar 24, 2023

    @jakemac53
    ContributorAuthor

    That documentation should also be updated as well to just always tell you to add the flutter_test dependency I suppose?

    It feels a bit weird, but it does make sense, based on how the flutter test command ships. If you run dart test without a test dependency it will make you add that dependency, FWIW. So it also makes sense for flutter test to require a flutter_test dependency, even if it technically can work without it, it isn't safe to run it without it.

  10. added a commit that references this issue on Mar 24, 2023
  11. changed the title [-]The `flutter test` command should require a `flutter_test` dependency.[/-] [+]The `flutter test` command should require a `flutter_test` or `test_api` dependency (and check for it).[/+] on Mar 24, 2023
  12. added
    P2Important issues not at the top of the work list
    on Mar 24, 2023
  13. 7 remaining items

  14. flutter-triage-bot commented on Nov 25, 2023

    @flutter-triage-bot

    This issue is assigned to @christopherfujino but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  15. jakemac53 commented on Dec 1, 2023

    @jakemac53
    ContributorAuthor

    @christopherfujino this is about to come up again when we change the wire format for the Runtime class here dart-lang/test#2144. This type of change should not be breaking but it ends up breaking because there is no forced constraint on package:test_api when using flutter test, so the wire format between the tool and the package don't line up.

    I think we can probably make it backwards compatible, but it would be great if we didn't have to, otherwise we are stuck with this tech debt until we decide to knowingly break users on some older version of flutter.

  16. christopherfujino commented on Dec 1, 2023

    @christopherfujino
    Contributor

    @christopherfujino this is about to come up again when we change the wire format for the Runtime class here dart-lang/test#2144. This type of change should not be breaking but it ends up breaking because there is no forced constraint on package:test_api when using flutter test, so the wire format between the tool and the package don't line up.

    I think we can probably make it backwards compatible, but it would be great if we didn't have to, otherwise we are stuck with this tech debt until we decide to knowingly break users on some older version of flutter.

    @jakemac53 thanks for the heads up! Assigning @eliasyishak to fix.

  17. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Dec 1, 2023
  18. christopherfujino commented on Apr 1, 2024

    @christopherfujino
    Contributor

    @eliasyishak is this still on your radar?

  19. eliasyishak commented on Apr 2, 2024

    @eliasyishak
    Contributor

    Still tracking on my todos but haven't got around to it yet as I figure out how to handle the breaking change that comes with it

  20. andrewkolos commented on Jul 9, 2024

    @andrewkolos
    Contributor

    Unassigning since I am not confident I will find time to work on this within the next 2-4 weeks.

  21. removed their assignment
    on Jul 9, 2024
  22. self-assigned this
    on Feb 22, 2025
  23. removed their assignment
    on Mar 19, 2025
  24. added
    tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.
    on Jul 11, 2025
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: proposalA detailed proposal for a change to Flutterteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions