Skip to content

Add an example to test Landscape orientation in a widget test #2005

Description

@zoechi

@eseidelGoogle commented on Thu May 25 2017

@sethladd asked me how difficult it was to test landscape layouts in tests. I suspect it's straightforward to do, but I'm not aware of an example to give.


@Hixie commented on Thu May 25 2017

In practice all tests are landscape. :-)


@eseidelGoogle commented on Thu May 25 2017

It seems like we will want to explain to individuals in flutter.io/testing how to test landscape vs. portrait for their widgets (as well as layouts at different sizes). For our own widgets, coverage will tell us if we're testing the landscape vs. portrait configurations of course. e.g. https://coveralls.io/builds/11679479/source?filename=lib%2Fsrc%2Fmaterial%2Fdate_picker.dart#L101 (I'm not actually sure if that's telling me the portrait code is covered or not).


@Hixie commented on Thu May 25 2017

Indeed. Where's a good place to put this information? API docs? Where?


@eseidelGoogle commented on Thu May 25 2017

Presumably https://flutter.io/testing?


@zoechi commented on Wed Jun 27 2018

Related SO question https://stackoverflow.com/questions/50158364/in-flutter-widget-testing-how-to-make-media-orientation-to-portrait


@zoechi commented on Tue Dec 11 2018

Probably a better way (not tested, wasn't aware of that before) https://stackoverflow.com/questions/53706569/how-to-test-flutter-widgets-on-different-screen-sizes

Activity

  1. sfshaza2 commented on Jan 29, 2019

    @sfshaza2
    Contributor

    We have this, but could still use the info in the testing doc.

  2. added
    p1-highMajor but not urgent concern: Resolve in months. Update each month.
    on Jan 29, 2019
  3. zoechi commented on Jan 30, 2019

    @zoechi
    Author

    Orientation in testing is entirely different. See for example the last 2 links in the initial comment.
    There is no easy to find way how to specify screen dimension/orientation for tests.

  4. eggenstein commented on Mar 27, 2019

    @eggenstein

    There is no easy to find way how to specify screen dimension/orientation for tests.

    This works just fine for me:

    const double PORTRAIT_WIDTH = 400.0;
    const double PORTRAIT_HEIGHT = 800.0;
    const double LANDSCAPE_WIDTH = PORTRAIT_HEIGHT;
    const double LANDSCAPE_HEIGHT = PORTRAIT_WIDTH;
    
    final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
    
    await binding.setSurfaceSize(Size(PORTRAIT_WIDTH, PORTRAIT_HEIGHT));
    await tester.pumpWidget(MyWidget());
    
    // test in portrait
    
    await binding.setSurfaceSize(Size(LANDSCAPE_WIDTH, LANDSCAPE_HEIGHT));
    await tester.pumpAndSettle();
    
    // OrientationBuilder gets triggered
    
    // test in landscape
    
  5. changed the title [-]Would like an example of testing for Landscape in a widget test[/-] [+]Add an example to test Landscape orientation in a widget test[/+] on Jun 2, 2023
  6. added
    t.ui.generalRelates to general Flutter app UI topics
    p2-mediumNecessary but not urgent concern. Resolve when possible.
    test.widgetRelates to widget testing
    and removed
    p1-highMajor but not urgent concern: Resolve in months. Update each month.
    on Jun 2, 2023
  7. self-assigned this
    on Jan 29, 2025
  8. added a commit that references this issue on Feb 3, 2025
    61a368c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

e1-hoursEffort: < 8 hrsfix.examplesAdds or changes examplep2-mediumNecessary but not urgent concern. Resolve when possible.t.ui.generalRelates to general Flutter app UI topicstest.generalRelates to unit, integration, perf testingtest.widgetRelates to widget testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions