Skip to content

Move away from TestSemantics and towards fine grained semantics testing #184367

Description

@justinmc

Background

TestSemantics is used to quickly check that dumping a semantics tree produces some exact string. This is easy to set up, but is often a cause of unhelpful failures. For example, you may have made a small change to the widgets returned from a build method before only to be greeted by a large wall of text about how the semantics no longer matches.

How to test semantics instead

Instead, find the exact semantics node that is relevant to the given test using tester.semantics.find.

Migrating

This came up in #183790 (comment), where it was decided that we would duplicate TestSemantics in the new material_ui package instead of exposing it publicly in flutter_test, in order to avoid encouraging other people to use it. We should migrate all usages across flutter/flutter and material_ui to use the recommendation above, and then remove both instances of TestSemantics.

List of locations to migrate

rg -l TestSemantics
Test files that use TestSemantics

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions