dimanche 28 mars 2021

Flutter Integration test: I can't target some of my widgets - Getter not found

I am learning about integration testing in flutter and I'm running into a problem.

My app contains a sign-in button widget and my test starts with pumping it.

However, I can't seem to target it.

Every attempt results in the following error:

integration_test/doctor_integration_test.dart:21:24: Error: Getter not found: 'SignInPage'.
    expect(find.byType(SignInPage), findsOneWidget);
                       ^^^^^^^^^^
                                                                        
                                                                        
FAILURE: Build failed with an exception.

The SignInPage is called within:

MaterialApp _buildMaterialApp(BuildContext context) {
    return MaterialApp(
      title: 'Skinopathy: Doctor',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      routes: {
        '/': (context) {
          return BlocListener<AppBloc, AppState>(
            listener: (context, state) {
              if (state is AppAuthenticated) {
                Navigator.pushReplacement(
                  context,
                  MaterialPageRoute(
                    builder: (_) => WelcomePage(),
                  ),
                );
              } else if (state is AppUnauthenticated) {
                Navigator.pushReplacementNamed(context, '/sign_in');
              } else if (state is AppOutdated) {
                Navigator.pushReplacement(
                  context,
                  MaterialPageRoute(
                    builder: (_) => OutdatedVersionPage(),
                  ),
                );
              }
            },
            child: Center(
              child: SplashPage(),
            ),
          );
        },
        '/sign_in': (context) {
          return SignInPage();
        },

My presumption is that the integration takes place before the SignInPage is loaded.

_buildMaterialApp is also a child of Widget _buildRootLevelWidgets(BuildContext context)

How do I properly target SignInPage for testing?

Is there anything else I'm doing wrong?

Please note: I did NOT build this app; I'm just here to test it.

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire