Skip to content

Document the flutter_test dimensions and describe tricks for testing other dimensions #12994

Description

@robertoscaramuzzi

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.

Activity

  1. added
    a: tests"flutter test", flutter_test, or one of our tests
    on Nov 13, 2017
  2. tvolkert commented on Nov 13, 2017

    @tvolkert
    Contributor

    Potential options:

    1. Support flags to flutter_tester that affect the screen resolution in test_runner.cc
    2. Make AutomatedTestWidgetsFlutterBinding override createViewConfiguration() (like LiveTestWidgetsFlutterBinding does) to look for some hook to override the default resolution.
  3. tvolkert commented on Nov 13, 2017

    @tvolkert
    Contributor

    Actually it looks like:

    • #1 above is required.
    • That will make AutomatedTestWidgetsFlutterBinding automatically pick up the desired resolution.
    • We would need to update LiveTestWidgetsFlutterBinding to 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, a flutter run invocation of that test would yield a different resolution.
  4. Hixie commented on Nov 13, 2017

    @Hixie
    Contributor

    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.

  5. robertoscaramuzzi commented on Nov 14, 2017

    @robertoscaramuzzi
    ContributorAuthor

    Thanks, Hixie. That seems to work, but it's entirely non-obvious. It would be good to provide a better API.

  6. added this to the milestone on Nov 14, 2017
  7. Hixie commented on Nov 14, 2017

    @Hixie
    Contributor

    We should definitely document it, maybe provide some arguments to pumpWidget to do it for you.

  8. alanrussian commented on Dec 8, 2017

    @alanrussian
    Contributor

    IIRC the current default size isn't documented anywhere. That might be helpful to document too.

  9. alanrussian commented on May 21, 2018

    @alanrussian
    Contributor

    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 ListView that extends beyond the default viewport, the screenshot would capture the entire ListView. Also, if you have a widget less than the default viewport, it could capture an image that's just that widget's size.

  10. tvolkert commented on May 21, 2018

    @tvolkert
    Contributor

    At least the second use case is possible by inserting a RepaintBoundary in the hierarchy where you want to cap the screenshot.

  11. Hixie commented on May 21, 2018

    @Hixie
    Contributor

    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.

  12. alanrussian commented on May 21, 2018

    @alanrussian
    Contributor

    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

  13. tvolkert commented on Jun 12, 2018

    @tvolkert
    Contributor

    @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.

  14. 15 remaining items

  15. acoutts commented on Apr 19, 2020

    @acoutts

    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?

  16. removed this from the milestone on Jun 1, 2020
  17. jamesderlin commented on Jul 28, 2020

    @jamesderlin
    Contributor

    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.

    For simulating screen rotation, it seems that the SizedBox + MediaQuery approach might not behave quite like an actual screen rotation on a device. I've observed an actual screen rotation triggering Layer.attach without triggering Layer.addToScene, but changing the dimensions of a SizedBox seems to trigger both.

  18. markusaksli-nc commented on Jul 30, 2020

    @markusaksli-nc
    Contributor

    flutter/website#2005 is relevant as well here

  19. juanmendez commented on Jul 14, 2021

    @juanmendez

    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!

  20. dnfield commented on Aug 20, 2021

    @dnfield
    Contributor

    The correct way to do this is to call setSurfaceSize on the binding.

    E.g.

    tester.binding.setSurfaceSize(size);
  21. github-actions commented on Sep 3, 2021

    @github-actions

    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.

  22. locked as resolved and limited conversation to collaborators on Sep 3, 2021
  23. added
    P3Issues that are less important to the Flutter project
    and removed on Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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 Fluttercustomer: mulligan (g3)d: api docsIssues with https://api.flutter.dev/toolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions