0

I'm running test widgets on my Flutter app, to avoid overflow problems I had to set FlutterError.onError = ignoreOverflowErrors, also due to responsive layout app i needed to set a size of the screeen in the testing enviroment tester.binding.window.physicalSizeTestValue, these solutions solve all my problem and allow me to run successfully the test when i run the tests from the VS gui:

enter image description here

enter image description here

But when i try to run from the console "flutter test" all the tests fails due to they cannot found widget in the lower part of the screen.

Can someone help me to fix it?


Below i attach my tests:
void main() {
  final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
  FlutterError.onError = ignoreOverflowErrors;
  //FlutterError.onError = null;
  testWidgets("Login Empty Input", (WidgetTester tester) async {
    tester.binding.window.physicalSizeTestValue = Size(1280, 900);
    tester.binding.window.devicePixelRatioTestValue = 1.0;
    //build the widget
    FlutterError.onError = ignoreOverflowErrors;
    await tester.pumpWidget(MaterialApp.router(routerConfig: _router));

    //find the widget
    final emailField = find.byKey(const Key("mail"));
    expect(emailField, findsOneWidget);

    final passwordField = find.byKey(const Key("password"));
    expect(passwordField, findsOneWidget);

    final button = find.byKey(const Key("signInButton"));
    expect(button, findsOneWidget);

    await tester.tap(button);
    await tester.pump();

    expect(find.text("Please enter your email"), findsOneWidget);
    expect(find.text("Please enter your Password"), findsOneWidget);
  });

//use only the part of the app needed
final GoRouter _router = GoRouter(routes: <RouteBase>[
  GoRoute(
      path: '/',
      builder: (BuildContext context, GoRouterState state) {
        //da qua vedere come e se cambiarlo
        return const LoginScreen();
      },
      routes: <RouteBase>[
        GoRoute(
            path: 'courses',
            builder: (BuildContext context, GoRouterState state) {
              return const CoursesScreen();
            })
      ])
]);

i've tried to solve the problem using a MediaQuery, and also setSurfaceSize from this questions but it do not work.

Gpp22
  • 43
  • 1
  • 9

0 Answers0