Skip to content

WidgetTester.tap() to stop ignoring failure #88759

Description

@mleonhard

Use case

Most mobile apps use tapping as the primary interaction method. App tests must use WidgetTester.tap() which is inherited from WidgetController.tap(). When tap() fails to find the target widget, it ignores this and continues. Failing to tap puts the app into an unintended state.

In the best case the test detects this problem and fails later. Then the engineer must waste time back-tracking to find out why the test failed.

In the worst case, the test silently does not test the behavior it is designed to test. Then bugs end up in production and users suffer and the business loses money.

When tap() fails to tap, it prints out a warning. Such warnings are easily missed in long test logs. This is especially true when logs include print-debugging (#88756). tap() takes an optional kwarg to suppress the warning.

Proposal

  1. Rename tap() to tryTap() and make it return true when it successfully tapped.
  2. Add a new tap() function that instantly fails the test if it cannot perform its intended purpose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our testsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: integration_testThe flutter/packages/integration_test pluginframeworkflutter/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