Repository navigation
Document the flutter_test dimensions and describe tricks for testing other dimensions #12994
Description
Activity
- addeda: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our tests
on Nov 13, 2017 Potential options:
- Support flags to
flutter_testerthat affect the screen resolution in test_runner.cc MakeAutomatedTestWidgetsFlutterBindingoverridecreateViewConfiguration()(likeLiveTestWidgetsFlutterBindingdoes) to look for some hook to override the default resolution.
- Support flags to
Actually it looks like:
- #1 above is required.
- That will make
AutomatedTestWidgetsFlutterBindingautomatically pick up the desired resolution. - We would need to update
LiveTestWidgetsFlutterBindingto provide a hook whereby the developer could specify the fixed resolution in which they want to run. Otherwise, even though the real test was run in a resolution specified by the developer, aflutter runinvocation of that test would yield a different resolution.
Just wrap the widget under test in a SizedBox (contained in a Center) with the given size. Optionally add a MediaQuery in there too if that matters.
Reacted by Erick Ghaumez and Günter Zöchbauerrobertoscaramuzzi commented
on Nov 14, 2017 ContributorAuthorMore actionsThanks, Hixie. That seems to work, but it's entirely non-obvious. It would be good to provide a better API.
Reacted by John MacPherson- addedc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capability
on Nov 14, 2017 We should definitely document it, maybe provide some arguments to pumpWidget to do it for you.
IIRC the current default size isn't documented anywhere. That might be helpful to document too.
Not sure how much this is related but it would be useful if we could take full-page screenshots of entire widgets for screenshot tests. For example: if you have a
ListViewthat extends beyond the default viewport, the screenshot would capture the entireListView. Also, if you have a widget less than the default viewport, it could capture an image that's just that widget's size.At least the second use case is possible by inserting a
RepaintBoundaryin the hierarchy where you want to cap the screenshot.ListViews don't go beyond the viewport. That's sort of the entire point of a ListView. :-) They don't even reify the widgets that aren't visible.
You could always create a RepaintBoundary around a SizedBox that is the size you want, though, and put the ListView inside that.
Thanks, Todd. That's exactly what I was looking for.
Ian, I guess maybe what I'm asking for just not possible to implement with the design of
ListViews. I'm basically asking for what you describe in your second paragraph but for it to somehow know how large the screen is. Maybe we could create our own implementation by scrolling the screen down until it won't scroll anymore and determining the height. cc @johnfesa@Hixie, @paolosoares reports that he'd like to not just change the size of the produced image -- he'd like to change the constraints so that the widget lays out differently.
15 remaining items
Is there any solution to this? I can't get my widget test to run because of a phantom overflow somewhere.
I tried adjusting MediaQuery and this:
final size = Size(414, 896); await binding.setSurfaceSize(size); binding.window.physicalSizeTestValue = size; tester.binding.window.devicePixelRatioTestValue = 1;
But I can't fix this overflow. Those dimensions are the same as the iphone simulator and it runs fine in that. How can we fix widget test sizing?
Reacted by Michael SödermanJust wrap the widget under test in a SizedBox (contained in a Center) with the given size. Optionally add a MediaQuery in there too if that matters.
For simulating screen rotation, it seems that the
SizedBox+MediaQueryapproach might not behave quite like an actual screen rotation on a device. I've observed an actual screen rotation triggeringLayer.attachwithout triggeringLayer.addToScene, but changing the dimensions of aSizedBoxseems to trigger both.- addedc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutter
on Jul 30, 2020 flutter/website#2005 is relevant as well here
This worked for me
setUp(() { WidgetsBinding.instance.renderView.configuration = new TestViewConfiguration(size: const Size(1200.0, 1980.0)); });
it was just magic when dealing with an app made for a tablet. thank you!
The correct way to do this is to call
setSurfaceSizeon the binding.E.g.
tester.binding.setSurfaceSize(size);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 -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Sep 3, 2021 - addedP3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectand removed
on Jun 28, 2023
Currently the size is fixed at 800 x 600, which makes it impossible to test behavior that happens only in portrait mode, as well as other size-dependent behavior.