Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TestWindow and TestWidgetsFlutterBinding.window for multi-window world #117481

Closed
Tracked by #116929
goderbauer opened this issue Dec 21, 2022 · 6 comments · Fixed by #121549, #122060, #122233 or #122422
Closed
Tracked by #116929
Assignees
Labels
a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. P1 High-priority issues at the top of the work list

Comments

@goderbauer
Copy link
Member

The SingletonWindow these are based on is going away as port of the multi window world. Replacements are FlutterView and PlatformDispatcher. An app can use multiple FlutterViews now. You should still be able to write simple widget tests (unit tests) and not care about windows/views at all.

@goderbauer goderbauer added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Dec 21, 2022
@goderbauer
Copy link
Member Author

@pdblasi-google I filed this as a placeholder issue for the work I talked to you about last week. Let's sync up in the new year to figure out the details.

@goderbauer goderbauer added the P1 High-priority issues at the top of the work list label Jan 3, 2023
@pdblasi-google
Copy link
Contributor

pdblasi-google commented Jan 20, 2023

@goderbauer and I went over some of the specifics of this today, here's the summary of the discussion:

New APIs

TestView

We need an API similar to the current TestWindow that people can change view specific properties (such as size of the view) for testing. For this a new TestView which will implement the parts of TestWindow that are not currently covered by TestPlatformDispatcher.

TestPlatformDispatcher will be adjusted so that any views requested by the application return a TestView instead of a regular View.

TestWidgetsFlutterBinding.view & TestWidgetsFlutterBinding.viewOf

For the likely most common case of a single view, we will add a view property to WidgetTester that will return the only view in TestPlatformDispatcher. If there is more than one view, this property will throw an exception.

There will also be a viewOf method that takes a finder and returns the nearest View in the widget tree above the result of the finder. This is intended to be similar to the View.of API for fetching the nearest View while in the app.

Old APIs

TestPlatformDispatcher will be adjusted to return TestViews when a View is requested.

TestWindow and the TestWidgetsFlutterBinding.window property will be deprecated. Usages of these will be pointed to the TestWidgetsFlutterBinding.platformDispatcher and TestWidgetsFlutterBinding.view properties.

Optional Improvements

Since we're deprecating TestWindow, we can take this chance to make setup and teardown of modifiable properties (such as view size) easier. Possibly in a few different ways:

  1. TestPlatformDispatcher could return new views per test, meaning that default values would always be reset.
  2. TestPlatformDispatcher and TestView could store and restore their own modifiable values at the beginning and end of each test respectively.

@pdblasi-google
Copy link
Contributor

This had to be reverted due to failures of web tests. Reopening.

@pdblasi-google
Copy link
Contributor

Reland was reverted due to failures in google tests. Reopening.

@pdblasi-google
Copy link
Contributor

Reland (2) was reverted due to failures in google tests. Reopening.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. P1 High-priority issues at the top of the work list
Projects
Status: Done
2 participants