-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Open
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 testsframeworkflutter/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, testWidgets does a lot of its setup and teardown outside of the package:test's setup and teardown system. This makes it difficult to use the standard setup/teardown functionality for organizing and optimizing widget tests.
Use case
As mentioned in #114468, there are a lot of test properties that would make sense to setup and teardown consistently, but we are unable to because the setup, teardown, and enforcement of state are all done outside of the setup/teardown system.
Proposal
Additions
- Add
setUpWidgets(WidgetTesterCallback callback)to allow for setting up widgets consistently- State from these methods (such as pumping a widget) should carry over into the test, allowing the test to focus on actions and expectations on a consistently pumped widget
- Add
tearDownWidgets(WidgetTesterCallback callback)to allow for adding teardowns that need access to theWidgetTester. - Add
addTearDownWidgets(WidgetTesterCallback callback)to allow for teardowns to be added within a test that need to access theWidgetTester.
Modifications
- Update
TestWidgetsFlutterBinding._runTestandTestWidgetsFlutterBinding._runTestBodyto use setups, teardowns, or the widget variants added above to do all of the setup for the test. - Update the current invariant checks to be invariant enforcement or remove them completely. If we can reset them, do. If we can't reset them, warn, but don't fail the test.
- This should also include resetting the various
on<PropertyChanged>callbacks forTestPlatformDispatcherandTestFlutterViewto prevent leaks between tests
- This should also include resetting the various
AlexanderArendar, radzish, damcur, Alex-Usmanov, guidotheelen and 8 more
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 testsframeworkflutter/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