Repository navigation
☔ Framework unit tests shouldn't cross-import libraries #177028
Copy link
Copy link
Open
1 / 51 of 5 issues completedOpen
1 / 51 of 5 issues completed
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
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:
| MaterialApp( |
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
- Test cross import lint #178693
- (Test cross-imports) Don't import Material in tests for convenience #177415
- (Test cross-imports) Tests should go in the library that they're testing #177414
- (Test cross-imports) No legacy Material imports in tests #177412
- Test README files should explain cross imports #179429
- (Test cross-imports) Don't cross-import test utils #182636
- [Decoupling] Unskip all skipped tests in material_ui and cupertino_ui #188395
- [cross imports] Check cross imports in /examples #187645
- [Decoupling] Migrate examples to material_ui and cupertino_ui #190093
- Minimize cross imports in examples #190305
Related
Data
| Reasons | Totals | Percentage |
|---|---|---|
| Legacy | 56 | 21.37% |
| Convenience | 127 | 48.47% |
| Misplacement | 57 | 21.76% |
| Legitimate cross-platform testing | 22 | 8.40% |
Confirmed acceptable cross-imports:
Located in Material, imported Cupertino
- test/material/progress_indicator_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/adaptive_text_selection_toolbar_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/slider_test.dart
- Located in Material, imported Cupertino
- Category: Legitimate cross-platform testing
- test/material/dialog_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/switch_list_tile_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/app_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/text_field_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/about_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/dropdown_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- Would be fixed by CupertinoScrollbar in SystemUI.
- test/material/checkbox_list_tile_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/radio_list_tile_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/page_transitions_theme_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- Page transitions in system ui
- test/material/scrollbar_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- Could be moved to Widgets if scrollbar was in System UI.
- test/material/switch_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/selection_area_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- Cupertino handle controls (system ui)
- test/material/magnifier_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/radio_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/theme_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- Giant section testing CupertinoTheme with Material stuff.
- test/material/text_form_field_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/checkbox_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/refresh_indicator_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- test/material/page_test.dart
- Located in Material, imported Cupertino.
- Category: Legitimate cross-platform testing
- Could be moved to Widgets if page transitions were in System UI.
- [test/material/tooltip_test.dart]
- Located in Material, imported Cupertino
- Category: Legitimate cross-platform testing
PRs:
#177029
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Type
Projects
- StatusShow more project fieldsIn Progress
- StatusShow more project fieldsTodo
Activity
[-]Framework unit tests shouldn't cross-import libraries[/-][+]☔ Framework unit tests shouldn't cross-import libraries[/+]Piinks commentedon Nov 4, 2025
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.
208 remaining items
Remove Material import from view chrome style test (flutter#186994)
Some cleanup of cross library test imports (#177029)
Remove unnecessary Material imports from non-Material tests in flutte…
Remove Material import from sliver tree rendering test (flutter#187000)
Remove Material imports from painting tests (flutter#186937)
Remove Material imports from rendering editable tests (flutter#186951)
Remove Material import from editable text cursor tests (flutter#186671)
Remove Material import from navigator replacement tests (flutter#186674)
Remove Material import from implicit animation tests (flutter#186673)
Remove Material import from view chrome style test (flutter#186994)
[material_ui] port drawer tests over from flutter/widgets (#12711)
[material_ui] port drawer tests over from flutter/widgets (flutter#12711
[material_ui] port drawer tests over from flutter/widgets (flutter#12711
Some cleanup of cross library test imports (#177029)
remove MaterialApp import from raw_radio_test.dart (#181721)