Skip to content

☔ Framework unit tests shouldn't cross-import libraries #177028

Open
1 of 5 issues completed
Open

Description

@justinmc

Currently, unit tests in the Widgets, Material, and Cupertino libraries freely import between each other, usually without a good reason. This is confusing for maintainers trying to determine test coverage and for contributors trying to decide where to place their tests.

For example, cupertino/magnifier_test.dart uses MaterialApp simply out of convenience or habit:

Instead, I propose that we should enforce the following structure:

  • The Widgets library unit tests should not import Material or Cupertino.
  • The Cupertino library should not import Material.
  • The Material library should contain all tests that require imports of multiple libraries.

Design doc: https://docs.google.com/document/d/1UHxALQqCbmgjnM1RNV9xE2pK3IGyx-UktGX1D7hYCjs/edit?tab=t.0

Sub-issues

Related

Data

Reasons Totals Percentage
Legacy 56 21.37%
Convenience 127 48.47%
Misplacement 57 21.76%
Legitimate cross-platform testing 22 8.40%
Image
Confirmed acceptable cross-imports:

Located in Material, imported Cupertino

PRs:
#177029

Activity

  1. self-assigned this
    on Oct 14, 2025
  2. changed the title [-]Framework unit tests shouldn't cross-import libraries[/-] [+]☔ Framework unit tests shouldn't cross-import libraries[/+] on Oct 22, 2025
  3. removed their assignment
    on Oct 22, 2025
  4. added
    in triagePresently being triaged by the triage team
    a: tests"flutter test", flutter_test, or one of our tests
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Oct 23, 2025
  5. self-assigned this
    on Oct 28, 2025
  6. added
    P1High-priority issues at the top of the work list
    on Oct 28, 2025
  7. Piinks commented on Nov 4, 2025

    @Piinks
    Contributor

    Perhaps another sub-issue: enforce structure with analysis, and introduce an allow list for current violations. That way we can gracefully migrate, and ensure new instance are not introduced from new PRs.

  8. moved this to In Progress in Decoupling Designon Nov 5, 2025
  9. 208 remaining items

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 Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions