Skip to content

(Test cross-imports) Don't import Material in tests for convenience #177415

Description

@justinmc

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

Tests shouldn't import the Material library simply out of convenience (such as to use MaterialApp instead of WidgetsApp). This will help with our general test organization and also help remove a devDependency after Material and Cupertino are decoupled from the framework.

How to fix

The tests listed below import Material when they shouldn't, typically to access something like MaterialApp. Don't just move these tests into the Material library. They should stay in the library of the file that they are testing.

  1. Find a test listed below that is not already fixed (checked) and that does not have a PR already linked.
  2. Replace the "convenient" widget imported from another library with something in the current library. If needed, create a helper to make it easier to accomplish the same thing in tests.
  3. When you open a PR, reference this issue as "Part of " instead of "Fixes", to avoid it being prematurely closed.
Widget What to do
Material This is probably used to wrap widgets that require a Material ancestor. If possible, just remove it, or replace it with something like Container. If not possible, consider replacing or removing the widget that depends on its presence.
MaterialApp @rkishan516 has created a TestWidgetsApp in #180506 to easily replace MaterialApp.
Colors Replace with Color and a hex value. Per offline discussion with @victorsanni, consider creating a utils file with convenient color constants, but only in the tests. Use prefixed names like debugRed, etc., to avoid collisions if used with static extensions and dot shorthands in the future. For colors that vary by index, like in a list, use getTestColors, added by @navaronbracke in #180994.
ListTile Use TestListTile, added by @huycozy in #180572.
Icons Remove if possible.
ElevatedButton Use TestButton, created by @navaronbracke in #180994.
Checkbox If it can't be removed, replace it with buildToggleable, and/or we should create a TestCheckbox or RawCheckbox.
MaterialPageRoute Use PageRouteBuilder.
Divider Remove it altogether if possible, otherwise use something like SizedBox. See @navaronbracke's work in #180999.
TextField Use TestTextField once #180494 is merged (thanks @Renzo-Olivares ).

Tests to fix:

Located in Widgets, imported Material

Located in Cupertino, imported Material

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues 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
    No fields configured for issues without a type.

    Projects

    Status
    In Progress
    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions