Is there a way to load a specific view in a Flutter app integration test?

473 Views Asked by At

I'm working on creating some integration tests for a complex app with many views. I have already managed to write some tests for user authentication - this was fairly simple because it required some initial setup (locators, Firebase initialization etc.) and pumping the main widget in the main.dart file.

Now, I would like to test some of the more downstream functionality (after the user has logged in), and instead of having to load the login view again and log in, I'd like the test to skip the authentication and open a specific view (e.g., a social wall view).

When running the following code:

await tester.pumpWidget(app.SocialWallView());

I get a MediaQuery related error, which I managed to fix using a solution found on StackOverflow. It involved defining a function within the test file which returns a MaterialApp:

  Widget createWidgetForTesting({Widget child}) {
    return MaterialApp(
      home: child,
    );
  }

and then running:

await tester.pumpWidget(createWidgetForTesting(child: new app.SocialWallView()));

When running this, however, I get multiple errors due to getters being called on null:

enter image description here

enter image description here

I have a feeling this could be a result of lack of setup; due to skipping the authentication step, the app doesn't know the user's name, and therefore a lot of data is missing.

Is there any neat way of loading downstream/specific views + loading the correct data to avoid hitting such exceptions?

I'm fairly new to Flutter and especially integration testing, so I'm thankful for any advice.

0

There are 0 best solutions below